replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / caprotocolmessage.c
old mode 100644 (file)
new mode 100755 (executable)
index 6f37b7a..4f2f4a0
@@ -247,6 +247,8 @@ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode,
     return outpdu;
 
 exit:
+    OIC_LOG(DEBUG, TAG, "data :");
+    OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t*) data, length);
     coap_delete_pdu(outpdu);
     return NULL;
 }
@@ -459,12 +461,14 @@ CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, int target
     {
         unsigned char uriBuffer[CA_MAX_URI_LENGTH] = { 0 };
         unsigned char *pBuf = uriBuffer;
-        size_t buflen = sizeof(uriBuffer);
-        int res = (target == COAP_OPTION_URI_PATH) ? coap_split_path(str, length, pBuf, &buflen) :
-                                                     coap_split_query(str, length, pBuf, &buflen);
+        size_t unusedBufferSize = sizeof(uriBuffer);
+        int res = (target == COAP_OPTION_URI_PATH) ? coap_split_path(str, length, pBuf, &unusedBufferSize) :
+                                                     coap_split_query(str, length, pBuf, &unusedBufferSize);
 
         if (res > 0)
         {
+            assert(unusedBufferSize < sizeof(uriBuffer));
+            size_t usedBufferSize = sizeof(uriBuffer) - unusedBufferSize;
             size_t prevIdx = 0;
             while (res--)
             {
@@ -478,11 +482,13 @@ CAResult_t CAParseUriPartial(const unsigned char *str, size_t length, int target
                 }
 
                 size_t optSize = COAP_OPT_SIZE(pBuf);
-                if ((prevIdx + optSize) < buflen)
+                if (prevIdx + optSize > usedBufferSize)
                 {
-                    pBuf += optSize;
-                    prevIdx += optSize;
+                    assert(false);
+                    return CA_STATUS_INVALID_PARAM;
                 }
+                pBuf += optSize;
+                prevIdx += optSize;
             }
         }
         else
@@ -528,9 +534,7 @@ CAResult_t CAParseHeadOption(uint32_t code, const CAInfo_t *info, coap_list_t **
         }
         else
         {
-            OIC_LOG_V(DEBUG, TAG, "Head opt ID: %d", id);
-            OIC_LOG_V(DEBUG, TAG, "Head opt data: %s", (info->options + i)->optionData);
-            OIC_LOG_V(DEBUG, TAG, "Head opt length: %d", (info->options + i)->optionLength);
+            OIC_LOG_V(DEBUG, TAG, "Head opt ID[%d], length[%d]", id, (info->options + i)->optionLength);
             int ret = coap_insert(optlist,
                                   CACreateNewOptionNode(id, (info->options + i)->optionLength,
                                                         (info->options + i)->optionData),
@@ -1011,7 +1015,7 @@ CAResult_t CAGetTokenFromPDU(const coap_hdr_transport_t *pdu_hdr,
     coap_get_token2(pdu_hdr, transport, &token, &token_length);
 
     // set token data
-    if (token_length > 0)
+    if (token && token_length > 0)
     {
         OIC_LOG_V(DEBUG, TAG, "token len:%d", token_length);
         outInfo->token = (char *) OICMalloc(token_length);
@@ -1176,6 +1180,7 @@ bool CAIsSupportedBlockwiseTransfer(CATransportAdapter_t adapter)
     {
         return true;
     }
+    OIC_LOG_V(DEBUG, TAG, "adapter value of BWT is %d", adapter);
     return false;
 }
 #endif
@@ -1188,6 +1193,7 @@ bool CAIsSupportedCoAPOverTCP(CATransportAdapter_t adapter)
     {
         return true;
     }
+    OIC_LOG_V(DEBUG, TAG, "adapter value of CoAP/TCP is %d", adapter);
     return false;
 }
 #endif