2
0
mirror of git://github.com/lxc/lxc synced 2025-08-31 04:59:37 +00:00

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

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;