From 2dc16c391e94aef3136d3a7aa043750296d1a1db Mon Sep 17 00:00:00 2001 From: Omkar Hegde Date: Fri, 3 Oct 2014 11:19:52 -0700 Subject: [PATCH] 1.Optimization to reduce number of strlen() calls. 2. Removed the extra blank line. 3. '?' is no longer considered a part of the query Change-Id: Ieabc1352a4cccc504ae1caac59b154aa7a9c0997 --- csdk/stack/src/ocstack.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/csdk/stack/src/ocstack.c b/csdk/stack/src/ocstack.c index 53b10a1..78aa0d0 100644 --- a/csdk/stack/src/ocstack.c +++ b/csdk/stack/src/ocstack.c @@ -317,32 +317,34 @@ OCStackResult OCStop() /** * Verify the lengths of the URI and the query separately * - * @param inputUri - Input URI and query + * @param inputUri - Input URI and query. + * @param uriLen - The length of the initial URI with query. * - * Note: The '?' that appears after the URI is considered as + * Note: The '?' that appears after the URI is not considered as * a part of the query. */ OCStackResult verifyUriQueryLength(const char *inputUri, uint16_t uriLen) { char *query; - uint16_t queryLen = 0; query = strchr (inputUri, '?'); + if (query != NULL) { - queryLen = strlen (query); - } + if((query - inputUri) > MAX_URI_LENGTH) + { + return OC_STACK_INVALID_URI; + } - if (queryLen > MAX_QUERY_LENGTH) - { - return OC_STACK_INVALID_URI; + if((inputUri + uriLen - 1 - query) > MAX_QUERY_LENGTH) + { + return OC_STACK_INVALID_QUERY; + } } - - if ((uriLen - queryLen) > MAX_URI_LENGTH) + else if(uriLen > MAX_URI_LENGTH) { - return OC_STACK_INVALID_QUERY; + return OC_STACK_INVALID_URI; } - return OC_STACK_OK; } -- 2.7.4