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