net: zoap: Fix NULL pointer access

The code was setting pointer to null and then access it.

Coverity-CID: 157575

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2017-05-24 13:41:02 +03:00
commit 7bed585c42

View file

@ -28,7 +28,7 @@ static bool match_path_uri(const char * const *path,
const char *uri, u16_t len) const char *uri, u16_t len)
{ {
const char * const *p = NULL; const char * const *p = NULL;
int i, j, plen; int i, j, k, plen;
if (!path) { if (!path) {
return false; return false;
@ -46,31 +46,43 @@ static bool match_path_uri(const char * const *path,
return false; return false;
} }
/* Go through uri and try to find a matching path */
for (i = 1; i < len; i++) { for (i = 1; i < len; i++) {
if (!*p) { while (*p) {
return false; plen = strlen(*p);
k = i;
for (j = 0; j < plen; j++) {
if (uri[k] == '*') {
if ((k + 1) == len) {
return true;
}
} }
if (!p) { if (uri[k] != (*p)[j]) {
p++; goto next;
plen = *p ? strlen(*p) : 0;
j = 0;
} }
if (j == plen && uri[i] == '/') { k++;
p = NULL;
continue;
} }
if (uri[i] == '*' && i + 1 == len) { if (i == (k - 1) && j == plen) {
return true; return true;
} }
if (uri[i] != (*p)[j]) { if (k == len && j == plen) {
return false; return true;
} }
j++; next:
p++;
}
}
/* Did we find the resource or not */
if (i == len && !*p) {
return false;
} }
return true; return true;