Fix potential nil pointer error in msg allocation 45/45/1
authorE. Scott Daniels <daniels@research.att.com>
Tue, 9 Apr 2019 19:59:42 +0000 (19:59 +0000)
committerE. Scott Daniels <daniels@research.att.com>
Tue, 9 Apr 2019 19:59:42 +0000 (19:59 +0000)
Header pointer returned by NNG function was not checked for
nil value and could result in nil pointer use.

Change-Id: Ib30c148c27a0304fe10b85fe2e9cb2a6349ca26e
Signed-off-by: E. Scott Daniels <daniels@research.att.com>
src/nng/src/sr_nng_static.c

index 8e326e3..a99b3de 100644 (file)
@@ -131,8 +131,9 @@ static rmr_mbuf_t* alloc_zcmsg( uta_ctx_t* ctx, rmr_mbuf_t* msg, int size, int s
        }
 
        msg->header = nng_msg_body( msg->tp_buf );
-       hdr = (uta_mhdr_t *) msg->header;
-       hdr->rmr_ver = RMR_MSG_VER;                                                             // version info should we need to recognised old style messages someday
+       if( (hdr = (uta_mhdr_t *) msg->header) != NULL ) {
+               hdr->rmr_ver = RMR_MSG_VER;                                                             // version info should we need to recognised old style messages someday
+       }
        msg->len = 0;                                                                                   // length of data in the payload
        msg->alloc_len = mlen;                                                                  // length of allocated payload
        msg->payload = msg->header + sizeof( uta_mhdr_t );              // point past header to payload (single buffer allocation above)