IOT-1513: Incorrect URI parsing in OCDoResource
authorDave Thaler <dthaler@microsoft.com>
Fri, 4 Nov 2016 00:46:53 +0000 (17:46 -0700)
committerAshok Babu Channa <ashok.channa@samsung.com>
Tue, 8 Nov 2016 07:28:13 +0000 (07:28 +0000)
RFC 6874 support was missing from ParseRequestUri

Change-Id: I023745e76a4d14dc6d786a6423eaf80d5d71e428
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14009
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Habib Virji <habib.virji@samsung.com>
Reviewed-by: David Antler <david.a.antler@intel.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/stack/src/ocstack.c

index dcfa88d..b5781c7 100644 (file)
@@ -2533,7 +2533,27 @@ static OCStackResult ParseRequestUri(const char *fullUri,
         {
             return OC_STACK_NO_MEMORY;
         }
-        OICStrcpyPartial(da->addr, sizeof(da->addr), start, len);
+
+        // Decode address per RFC 6874.
+        char *percent = strchr(start, '%');
+        if (!percent || (percent > end))
+        {
+            OICStrcpyPartial(da->addr, sizeof(da->addr), start, len);
+        }
+        else
+        {
+            if (percent[1] != '2' || percent[2] != '5')
+            {
+                OICFree(*devAddr);
+                return OC_STACK_INVALID_URI;
+            }
+
+            int addrlen = percent - start + 1;
+            OICStrcpyPartial(da->addr, sizeof(da->addr), start, addrlen);
+            OICStrcpyPartial(da->addr + addrlen, sizeof(da->addr) - addrlen,
+                             percent + 3, end - percent - 3);
+        }
+
         da->port = port;
         da->adapter = adapter;
         da->flags = flags;