Klockwork fixes on C samples
authorMandeep Shetty <mandeep.shetty@intel.com>
Tue, 17 Mar 2015 20:55:11 +0000 (13:55 -0700)
committerErich Keane <erich.keane@intel.com>
Mon, 30 Mar 2015 17:00:19 +0000 (17:00 +0000)
Send MAX_HEADER_OPTION_DATA_LENGTH as buffer size to avoid array bounds
violation by potentially sending a larger size contained in the
optionLength field in received headers.

Change-Id: If9f6ea0688298a2ba7723db67f5082509fad1d5f
Signed-off-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/493
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientbasicops.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/occlientslow.cpp
resource/csdk/stack/samples/linux/SimpleClientServer/ocserver.cpp

index 9dce85f..3ed35e2 100644 (file)
@@ -230,8 +230,9 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse
             {
                 OC_LOG_V(INFO, TAG, "Received option with OC_COAP_ID and ID %u with",
                         ((OCHeaderOption)rcvdOptions[i]).optionID );
+
                 OC_LOG_BUFFER(INFO, TAG, ((OCHeaderOption)rcvdOptions[i]).optionData,
-                        ((OCHeaderOption)rcvdOptions[i]).optionLength);
+                    MAX_HEADER_OPTION_DATA_LENGTH);
             }
         }
     }
index e126035..1f6051d 100644 (file)
@@ -207,8 +207,9 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle,
                 {
                     OC_LOG_V(INFO, TAG, "Received option with OC_COAP_ID and ID %u with",
                             ((OCHeaderOption)rcvdOptions[i]).optionID );
+
                     OC_LOG_BUFFER(INFO, TAG, ((OCHeaderOption)rcvdOptions[i]).optionData,
-                            ((OCHeaderOption)rcvdOptions[i]).optionLength);
+                        MAX_HEADER_OPTION_DATA_LENGTH);
                 }
             }
         }
index a31b9c7..6a9a66e 100644 (file)
@@ -116,8 +116,9 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle handle, OCClientResponse
             {
                 OC_LOG_V(INFO, TAG, "Received option with OC_COAP_ID and ID %u with",
                         ((OCHeaderOption)rcvdOptions[i]).optionID );
+
                 OC_LOG_BUFFER(INFO, TAG, ((OCHeaderOption)rcvdOptions[i]).optionData,
-                        ((OCHeaderOption)rcvdOptions[i]).optionLength);
+                    MAX_HEADER_OPTION_DATA_LENGTH);
             }
         }
     }
index dbfeec7..acd3f13 100644 (file)
@@ -591,8 +591,9 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
                     {
                         OC_LOG_V(INFO, TAG, "Received option with OC_COAP_ID and ID %u with",
                                 ((OCHeaderOption)rcvdOptions[i]).optionID );
+
                         OC_LOG_BUFFER(INFO, TAG, ((OCHeaderOption)rcvdOptions[i]).optionData,
-                                ((OCHeaderOption)rcvdOptions[i]).optionLength);
+                            MAX_HEADER_OPTION_DATA_LENGTH);
                     }
                 }
                 OCHeaderOption * sendOptions = response.sendVendorSpecificHeaderOptions;