From: Michael Wallner Date: Wed, 14 Sep 2016 07:39:59 +0000 (+0200) Subject: coverity fixes X-Git-Tag: RELEASE_2_6_0_RC1~8 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=749dbbaa0e7c5e33d27121dab0f53bda85a67339;p=m6w6%2Fext-http coverity fixes --- diff --git a/src/php_http_buffer.c b/src/php_http_buffer.c index eaebfa0..64e559a 100644 --- a/src/php_http_buffer.c +++ b/src/php_http_buffer.c @@ -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; } } diff --git a/src/php_http_encoding.c b/src/php_http_encoding.c index 286f2b5..6d32652 100644 --- a/src/php_http_encoding.c +++ b/src/php_http_encoding.c @@ -222,7 +222,7 @@ retry_raw_inflate: } inflateEnd(&Z); - if (decoded_len && *decoded) { + if (*decoded_len && *decoded) { efree(*decoded); } } diff --git a/src/php_http_env_response.c b/src/php_http_env_response.c index 20a31eb..b4927a1 100644 --- a/src/php_http_env_response.c +++ b/src/php_http_env_response.c @@ -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); diff --git a/src/php_http_etag.c b/src/php_http_etag.c index 4e5fd69..4d34d57 100644 --- a/src/php_http_etag.c +++ b/src/php_http_etag.c @@ -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 diff --git a/src/php_http_filter.c b/src/php_http_filter.c index b6d967b..9b39104 100644 --- a/src/php_http_filter.c +++ b/src/php_http_filter.c @@ -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); diff --git a/src/php_http_message.c b/src/php_http_message.c index 60569b8..3186b79 100644 --- a/src/php_http_message.c +++ b/src/php_http_message.c @@ -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;