From: 2xsec Date: Tue, 4 Sep 2018 02:10:18 +0000 (+0900) Subject: utils: defensive programming X-Git-Tag: lxc-3.1.0~119^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91d9cab6dea7bbe93bf3a990b225c8fc8a45c39b;p=thirdparty%2Flxc.git 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 --- diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 77ad76b49..9795b51b6 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -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;