* [PATCH] lib/strutils.c: Move array bounds check in string_to_idarray() to appropriate place.
@ 2012-02-23 9:17 Heiko Carstens
2012-02-23 9:57 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Heiko Carstens @ 2012-02-23 9:17 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux, Chandan B Rajenda, Heiko Carstens
From: Chandan B Rajenda <chandan@linux.vnet.ibm.com>
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 | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/strutils.c b/lib/strutils.c
index 7586160..c40daf2 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;
--
1.7.9
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-02-23 9:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-23 9:17 [PATCH] lib/strutils.c: Move array bounds check in string_to_idarray() to appropriate place Heiko Carstens
2012-02-23 9:57 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox