You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ga...@apache.org on 2017/05/11 01:49:20 UTC

[trafficserver] branch master updated: Coverity 1022122, 1022123, 1022125: Dereference before null check

This is an automated email from the ASF dual-hosted git repository.

gancho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  d7e85e5   Coverity 1022122, 1022123, 1022125: Dereference before null check
d7e85e5 is described below

commit d7e85e51e79e5c326e255d6f0caab0a7c9238e5e
Author: Gancho Tenev <ga...@apache.com>
AuthorDate: Wed May 10 12:38:00 2017 -0700

    Coverity 1022122, 1022123, 1022125: Dereference before null check
    
    Problem:
    CID 1022122 (#1 of 1): Dereference before null check (REVERSE_INULL)
    check_after_deref: Null-checking txn_sm->q_client_request_buffer suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
    CID 1022123 (#1 of 1): Dereference before null check (REVERSE_INULL)
    check_after_deref: Null-checking txn_sm->q_client_response_buffer suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
    CID 1022125 (#1 of 1): Dereference before null check (REVERSE_INULL)
    check_after_deref: Null-checking txn_sm->q_cache_read_buffer suggests that it may be null, but it has already been dereferenced on all paths leading to the check
    
    Fix:
    Checked the return values on each step instead of all at the end.
---
 example/protocol/TxnSM.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/example/protocol/TxnSM.c b/example/protocol/TxnSM.c
index db3005f..316fd72 100644
--- a/example/protocol/TxnSM.c
+++ b/example/protocol/TxnSM.c
@@ -160,10 +160,12 @@ state_start(TSCont contp, TSEvent event ATS_UNUSED, void *data ATS_UNUSED)
     return prepare_to_die(contp);
   }
 
-  txn_sm->q_client_request_buffer        = TSIOBufferCreate();
+  txn_sm->q_client_request_buffer = TSIOBufferCreate();
+  if (!txn_sm->q_client_request_buffer) {
+    return prepare_to_die(contp);
+  }
   txn_sm->q_client_request_buffer_reader = TSIOBufferReaderAlloc(txn_sm->q_client_request_buffer);
-
-  if (!txn_sm->q_client_request_buffer || !txn_sm->q_client_request_buffer_reader) {
+  if (!txn_sm->q_client_request_buffer_reader) {
     return prepare_to_die(contp);
   }
 
@@ -286,13 +288,20 @@ state_handle_cache_lookup(TSCont contp, TSEvent event, TSVConn vc)
     response_size = TSVConnCacheObjectSizeGet(txn_sm->q_cache_vc);
 
     /* Allocate IOBuffer to store data from the cache. */
-    txn_sm->q_client_response_buffer        = TSIOBufferCreate();
+    txn_sm->q_client_response_buffer = TSIOBufferCreate();
+    if (!txn_sm->q_client_response_buffer) {
+      return prepare_to_die(contp);
+    }
     txn_sm->q_client_response_buffer_reader = TSIOBufferReaderAlloc(txn_sm->q_client_response_buffer);
-    txn_sm->q_cache_read_buffer             = TSIOBufferCreate();
-    txn_sm->q_cache_read_buffer_reader      = TSIOBufferReaderAlloc(txn_sm->q_cache_read_buffer);
-
-    if (!txn_sm->q_client_response_buffer || !txn_sm->q_client_response_buffer_reader || !txn_sm->q_cache_read_buffer ||
-        !txn_sm->q_cache_read_buffer_reader) {
+    if (!txn_sm->q_client_response_buffer_reader) {
+      return prepare_to_die(contp);
+    }
+    txn_sm->q_cache_read_buffer = TSIOBufferCreate();
+    if (!txn_sm->q_cache_read_buffer) {
+      return prepare_to_die(contp);
+    }
+    txn_sm->q_cache_read_buffer_reader = TSIOBufferReaderAlloc(txn_sm->q_cache_read_buffer);
+    if (!txn_sm->q_cache_read_buffer_reader) {
       return prepare_to_die(contp);
     }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].