summaryrefslogtreecommitdiffstats
path: root/lib/strutils.c
diff options
context:
space:
mode:
authorChandan B Rajenda2012-02-23 10:17:28 +0100
committerKarel Zak2012-02-23 10:54:25 +0100
commit179b923a19c717bcf03c2921c1c80dfebbb7075a (patch)
treed243280e7d7cbd9e7d862b1bcb73326a3d2c013e /lib/strutils.c
parentlibblkid: add BLKID_PARTS_MAGIC to blkid_do_wipe() docs (diff)
downloadkernel-qcow2-util-linux-179b923a19c717bcf03c2921c1c80dfebbb7075a.tar.gz
kernel-qcow2-util-linux-179b923a19c717bcf03c2921c1c80dfebbb7075a.tar.xz
kernel-qcow2-util-linux-179b923a19c717bcf03c2921c1c80dfebbb7075a.zip
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 <chandan@linux.vnet.ibm.com> Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Diffstat (limited to 'lib/strutils.c')
-rw-r--r--lib/strutils.c4
1 files changed, 2 insertions, 2 deletions
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;