]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/strutils: move array bounds check in string_to_idarray() to appropriate place.
authorChandan B Rajenda <chandan@linux.vnet.ibm.com>
Thu, 23 Feb 2012 09:17:28 +0000 (10:17 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Feb 2012 09:54:25 +0000 (10:54 +0100)
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 <chandan@linux.vnet.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
lib/strutils.c

index 75861607e594f774479f80d64e81278c65fbc3c0..c40daf2000c474d99078dc7ed283443c16583f43 100644 (file)
@@ -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;