Fix segfault due to calling strlen on null payload.
authorMandeep Shetty <mandeep.shetty@intel.com>
Wed, 13 May 2015 18:14:16 +0000 (11:14 -0700)
committerErich Keane <erich.keane@intel.com>
Wed, 13 May 2015 21:20:27 +0000 (21:20 +0000)
Some messages like ACKs, RESETs and others have null payload.
strlen was called in the function args which caused a seg fault.
Added check for null before calling strlen and moved call outside of
args list.

Change-Id: Ia97d48e662c220f73eec56bd260ed1f6c94dab90
Signed-off-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/979
Reviewed-by: Erich Keane <erich.keane@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
resource/csdk/connectivity/src/caprotocolmessage.c

index 456d423..34c1bd8 100644 (file)
@@ -170,8 +170,8 @@ coap_pdu_t *CAGeneratePDU(const char *uri, uint32_t code, const CAInfo_t info)
             coap_delete_list(optlist);
             return NULL;
         }
-
-        pdu = CAGeneratePDUImpl((code_t) code, optlist, info, info.payload, strlen(info.payload));
+        size_t lenPayload = info.payload ? strlen(info.payload) : 0;
+        pdu = CAGeneratePDUImpl((code_t) code, optlist, info, info.payload, lenPayload);
         if (NULL == pdu)
         {
             OIC_LOG(ERROR, TAG, "pdu NULL");