]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: defensive programming
author2xsec <dh48.jeong@samsung.com>
Tue, 4 Sep 2018 02:10:18 +0000 (11:10 +0900)
committer2xsec <dh48.jeong@samsung.com>
Tue, 4 Sep 2018 02:10:18 +0000 (11:10 +0900)
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>
src/lxc/utils.c

index 77ad76b498b2edc5548612009c1644df9d29bc8e..9795b51b668a1978c803c10c672b43218dc216e8 100644 (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;