coverity fixes
authorMichael Wallner <mike@php.net>
Wed, 14 Sep 2016 07:39:59 +0000 (09:39 +0200)
committerMichael Wallner <mike@php.net>
Wed, 14 Sep 2016 07:39:59 +0000 (09:39 +0200)
src/php_http_buffer.c
src/php_http_encoding.c
src/php_http_env_response.c
src/php_http_etag.c
src/php_http_filter.c
src/php_http_message.c

index eaebfa03e7e3e477fc97ccecd907b7b1169d716f..64e559a5907f0c8a051d350d3511f8863fa9a683 100644 (file)
@@ -32,9 +32,13 @@ PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(php_http_buffer_t
 
 PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex(php_http_buffer_t *buf, const char *string, size_t length)
 {
+       int free_buf = !!buf;
+
        if ((buf = php_http_buffer_init(buf))) {
                if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(buf, string, length)) {
-                       pefree(buf, buf->pmem);
+                       if (free_buf) {
+                               pefree(buf, buf->pmem);
+                       }
                        buf = NULL;
                }
        }
index 286f2b5751eac1b703c44b0fa2063716d431582f..6d32652a7acd43278339238d0fba46726e49a01f 100644 (file)
@@ -222,7 +222,7 @@ retry_raw_inflate:
                }
                inflateEnd(&Z);
 
-               if (decoded_len && *decoded) {
+               if (*decoded_len && *decoded) {
                        efree(*decoded);
                }
        }
index 20a31eb90fea41b0ad73aa22c9e8011867dc1c95..b4927a16b9553e86191deaa6d53937a0ff75a851 100644 (file)
@@ -369,10 +369,6 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t
                zval_ptr_dtor(&zoption);
        }
 
-       if (ret != SUCCESS) {
-               return ret;
-       }
-
        if ((zoption = get_option(options, ZEND_STRL("responseCode") TSRMLS_CC))) {
                zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
 
index 4e5fd692bf6ed8a91816fd28b6b9979ac017c550..4d34d57cd86571c77ebd04ee93b90ab8ffd380d1 100644 (file)
@@ -80,7 +80,7 @@ char *php_http_etag_finish(php_http_etag_t *e)
 #ifdef PHP_HTTP_HAVE_HASH
                const php_hash_ops *eho = NULL;
 
-               if (e->mode && (eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) {
+               if ((eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) {
                        eho->hash_final(digest, e->ctx);
                        etag = php_http_etag_digest(digest, eho->digest_size);
                }
@@ -110,7 +110,7 @@ size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t dat
 #ifdef PHP_HTTP_HAVE_HASH
                const php_hash_ops *eho = NULL;
 
-               if (e->mode && (eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) {
+               if ((eho = php_hash_fetch_ops(e->mode, strlen(e->mode)))) {
                        eho->hash_update(e->ctx, (const unsigned char *) data_ptr, data_len);
                }
 #endif
index b6d967b6f756eb27f62e57920086fabfa5655315..9b391048a22408cc95aa50df088b7f4813f59953 100644 (file)
@@ -302,7 +302,9 @@ static PHP_HTTP_FILTER_FUNCTION(zlib)
                
                nxt = ptr->next;
                php_stream_bucket_unlink(ptr TSRMLS_CC);
-               php_http_encoding_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len);
+               if (SUCCESS != php_http_encoding_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len)) {
+                       return PSFS_ERR_FATAL;
+               }
                
 #if DBG_FILTER
                fprintf(stderr, "update: deflate (-> %zu) (w: %zu, r: %zu)\n", encoded_len, stream->writepos, stream->readpos);
@@ -322,7 +324,9 @@ static PHP_HTTP_FILTER_FUNCTION(zlib)
                char *encoded = NULL;
                size_t encoded_len = 0;
                
-               php_http_encoding_stream_flush(buffer, &encoded, &encoded_len);
+               if (SUCCESS != php_http_encoding_stream_flush(buffer, &encoded, &encoded_len)) {
+                       return PSFS_ERR_FATAL;
+               }
                
 #if DBG_FILTER
                fprintf(stderr, "flush: deflate (-> %zu)\n", encoded_len);
@@ -340,7 +344,9 @@ static PHP_HTTP_FILTER_FUNCTION(zlib)
                char *encoded = NULL;
                size_t encoded_len = 0;
                
-               php_http_encoding_stream_finish(buffer, &encoded, &encoded_len);
+               if (SUCCESS != php_http_encoding_stream_finish(buffer, &encoded, &encoded_len)) {
+                       return PSFS_ERR_FATAL;
+               }
                
 #if DBG_FILTER
                fprintf(stderr, "finish: deflate (-> %zu)\n", encoded_len);
index 60569b8be62f336f2199ba72196c6fe1f8178e03..3186b79edca07ed13a09e982c9ced7bf64d5a239 100644 (file)
@@ -436,7 +436,7 @@ php_http_message_t *php_http_message_reverse(php_http_message_t *msg)
        if (c > 1) {
                php_http_message_t *tmp = msg, **arr;
 
-               arr = ecalloc(c, sizeof(**arr));
+               arr = ecalloc(c, sizeof(*arr));
                for (i = 0; i < c; ++i) {
                        arr[i] = tmp;
                        tmp = tmp->parent;
@@ -702,7 +702,7 @@ void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_D
                php_http_message_object_t **objects;
                int last;
 
-               objects = ecalloc(i, sizeof(**objects));
+               objects = ecalloc(i, sizeof(*objects));
 
                /* we are the first message */
                objects[0] = obj;