From: Dave Thaler Date: Fri, 4 Nov 2016 00:46:53 +0000 (-0700) Subject: IOT-1513: Incorrect URI parsing in OCDoResource X-Git-Tag: 1.3.0~1054^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c18f138f0a8c76e99500f7458f23bddef0f82e4e;p=platform%2Fupstream%2Fiotivity.git IOT-1513: Incorrect URI parsing in OCDoResource RFC 6874 support was missing from ParseRequestUri Change-Id: I023745e76a4d14dc6d786a6423eaf80d5d71e428 Signed-off-by: Dave Thaler Reviewed-on: https://gerrit.iotivity.org/gerrit/14057 Tested-by: jenkins-iotivity Reviewed-by: Habib Virji --- diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 1cde0da..b699b09 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -2507,7 +2507,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;