From: Chandan B Rajenda Date: Thu, 23 Feb 2012 09:17:28 +0000 (+0100) Subject: lib/strutils: move array bounds check in string_to_idarray() to appropriate place. X-Git-Tag: v2.21~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=179b923a19c717bcf03c2921c1c80dfebbb7075a;p=thirdparty%2Futil-linux.git lib/strutils: move array bounds check in string_to_idarray() to appropriate place. string_to_idarray() will incorrectly exit with an error when the last element of the passed in array gets filled. However it should only exit with an error if there is more input. To fix this move the array bounds check. Signed-off-by: Chandan B Rajenda Signed-off-by: Heiko Carstens --- diff --git a/lib/strutils.c b/lib/strutils.c index 75861607e5..c40daf2000 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -393,6 +393,8 @@ int string_to_idarray(const char *list, int ary[], size_t arysz, const char *end = NULL; int id; + if (n >= arysz) + return -2; if (!begin) begin = p; /* begin of the column name */ if (*p == ',') @@ -408,8 +410,6 @@ int string_to_idarray(const char *list, int ary[], size_t arysz, if (id == -1) return -1; ary[ n++ ] = id; - if (n >= arysz) - return -2; begin = NULL; if (end && !*end) break;