From 179b923a19c717bcf03c2921c1c80dfebbb7075a Mon Sep 17 00:00:00 2001 From: Chandan B Rajenda Date: Thu, 23 Feb 2012 10:17:28 +0100 Subject: 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 --- lib/strutils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/strutils.c') diff --git a/lib/strutils.c b/lib/strutils.c index 75861607e..c40daf200 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; -- cgit v1.2.3-55-g7522