* [PATCH] utils: fix makeargs stack overflow
@ 2017-12-18 19:15 Stephen Hemminger
0 siblings, 0 replies; only message in thread
From: Stephen Hemminger @ 2017-12-18 19:15 UTC (permalink / raw)
To: netdev; +Cc: Stephen Hemminger
The makeargs() function did not handle end of string correctly
and would reference past end of string.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/utils.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/lib/utils.c b/lib/utils.c
index 7ced8c061cb0..df1f3b1238c0 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1206,10 +1206,16 @@ ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
int makeargs(char *line, char *argv[], int maxargs)
{
static const char ws[] = " \t\r\n";
- char *cp;
+ char *cp = line;
int argc = 0;
- for (cp = line + strspn(line, ws); *cp; cp += strspn(cp, ws)) {
+ while (*cp) {
+ /* skip leading whitespace */
+ cp += strspn(cp, ws);
+
+ if (*cp == '\0')
+ break;
+
if (argc >= (maxargs - 1)) {
fprintf(stderr, "Too many arguments to command\n");
exit(1);
@@ -1226,13 +1232,16 @@ int makeargs(char *line, char *argv[], int maxargs)
fprintf(stderr, "Unterminated quoted string\n");
exit(1);
}
- *cp++ = 0;
- continue;
+ } else {
+ argv[argc++] = cp;
+
+ /* find end of word */
+ cp += strcspn(cp, ws);
+ if (*cp == '\0')
+ break;
}
- argv[argc++] = cp;
- /* find end of word */
- cp += strcspn(cp, ws);
+ /* seperate words */
*cp++ = 0;
}
argv[argc] = NULL;
--
2.11.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2017-12-18 19:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-18 19:15 [PATCH] utils: fix makeargs stack overflow Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).