Skip to content

Commit da14019

Browse files
committed
Fixing stack smashing because of wrong edge condition in argument while loop.
1 parent 392b397 commit da14019

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

arg_parse.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int get_argc(char *s)
1313
sp++;
1414
if (*sp == '\0')
1515
return count;
16-
else
16+
else
1717
count++;
1818
while (!isspace(*sp) && *sp != '\0')
1919
sp++;
@@ -33,7 +33,7 @@ char **get_args(char *s, int index)
3333
{
3434
char **args, arg[BUFSIZE], *argp;
3535
int i;
36-
args = (char **) malloc (BUFSIZ);
36+
args = (char **) malloc (BUFSIZE);
3737

3838
s += index;
3939
_argc = get_argc(s);
@@ -48,7 +48,7 @@ char **get_args(char *s, int index)
4848
_argc--;
4949
goto top;
5050
}
51-
while (!isspace(*s) || *s == '\0')
51+
while (!isspace(*s) && *s != '\0')
5252
*argp++ = *s++;
5353

5454
*argp = '\0';

0 commit comments

Comments
 (0)