Fix broken observe requests and GETs being treated as OBSERVEs
authorMandeep Shetty <mandeep.shetty@intel.com>
Thu, 17 Sep 2015 23:47:21 +0000 (16:47 -0700)
committerSachin Agrawal <sachin.agrawal@intel.com>
Sun, 20 Sep 2015 05:01:26 +0000 (05:01 +0000)
args to some functions were validated for NULL to return error codes even though
NULLs were legal for the args.
For eg. it is legal for options to be NULL.

These incorrect validations caused early returns and observation actions
were not set to OC_OBSERVE_NO_OPTION which is 2. The field in the struct
instead defaulted to OC_OBSERVE_REGISTER = 0 due to default inits.

Fixed both by removing or replacing the incorrect validations with more
appropriate ones.

Change-Id: Ia7453227a668bb26971b2b7d84381f64151b88f9
Signed-off-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2659
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sachin Agrawal <sachin.agrawal@intel.com>
resource/csdk/stack/src/ocobserve.c
resource/csdk/stack/src/ocstack.c

index 6749105..6bcaa1c 100644 (file)
@@ -523,11 +523,17 @@ CreateObserveHeaderOption (CAHeaderOption_t **caHdrOpt,
                            uint8_t numOptions,
                            uint8_t observeFlag)
 {
-    if(!caHdrOpt || !ocHdrOpt)
+    if(!caHdrOpt)
     {
         return OC_STACK_INVALID_PARAM;
     }
 
+    if (numOptions > 0 && !ocHdrOpt)
+    {
+        OC_LOG (INFO, TAG, "options are NULL though number is non zero");
+        return OC_STACK_INVALID_PARAM;
+    }
+
     CAHeaderOption_t *tmpHdrOpt = NULL;
 
     tmpHdrOpt = (CAHeaderOption_t *) OICCalloc ((numOptions+1), sizeof(CAHeaderOption_t));
@@ -568,11 +574,10 @@ GetObserveHeaderOption (uint32_t * observationOption,
 
     if(!options || !numOptions)
     {
-        return OC_STACK_INVALID_PARAM;
+        OC_LOG (INFO, TAG, "No options present");
+        return OC_STACK_OK;
     }
 
-    *observationOption = OC_OBSERVE_NO_OPTION;
-
     for(uint8_t i = 0; i < *numOptions; i++)
     {
         if(options[i].protocolID == CA_COAP_ID &&
index 53beb1c..d2b13c9 100644 (file)
@@ -1607,6 +1607,12 @@ void HandleCARequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* reque
 
     // copy vendor specific header options
     uint8_t tempNum = (requestInfo->info.numOptions);
+
+    // Assume no observation requested and it is a pure GET.
+    // If obs registration/de-registration requested it'll be fetched from the
+    // options in GetObserveHeaderOption()
+    serverRequest.observationOption = OC_OBSERVE_NO_OPTION;
+
     GetObserveHeaderOption(&serverRequest.observationOption, requestInfo->info.options, &tempNum);
     if (requestInfo->info.numOptions > MAX_HEADER_OPTIONS)
     {