From 91d9cab6dea7bbe93bf3a990b225c8fc8a45c39b Mon Sep 17 00:00:00 2001 From: 2xsec Date: Tue, 4 Sep 2018 11:10:18 +0900 Subject: [PATCH] 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 --- src/lxc/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; -- 2.47.2