Skip to content

Commit

Permalink
utils: defensive programming
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2xsec authored and Christian Brauner committed Sep 30, 2018
1 parent 0d83e32 commit 6986ee5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lxc/utils.c
Expand Up @@ -891,10 +891,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;
Expand Down

0 comments on commit 6986ee5

Please sign in to comment.