utils: defensive programming

If caller passed the size of array not string length, it is possible to be accessed out of bounds.

Reorder conditions can prevent access invalid index of array.

Signed-off-by: 2xsec <dh48.jeong@samsung.com>
This commit is contained in:
2xsec 2018-09-04 11:10:18 +09:00
parent 22b67bfa96
commit 91d9cab6de
No known key found for this signature in database
GPG Key ID: 0BE2750EE612F372

View File

@ -898,10 +898,10 @@ static char *get_nextpath(char *path, int *offsetp, int fulllen)
if (offset >= fulllen)
return NULL;
while (path[offset] != '\0' && offset < fulllen)
while (offset < fulllen && path[offset] != '\0')
offset++;
while (path[offset] == '\0' && offset < fulllen)
while (offset < fulllen && path[offset] == '\0')
offset++;
*offsetp = offset;