Fix argv-fuzz.
#ifndef _HAVE_ARGV_FUZZ_INL
#define _HAVE_ARGV_FUZZ_INL
+#include <string.h>
#include <unistd.h>
#define AFL_INIT_ARGV() \
@@ -63,22 +64,22 @@ static char **afl_init_argv(int *argc) {
char *ptr = in_buf;
int rc = 0;
- if (read(0, in_buf, MAX_CMDLINE_LEN - 2) < 0) {}
-
- while (*ptr && rc < MAX_CMDLINE_PAR) {
+ ssize_t num = 0;
+ if ((num = read(0, in_buf, MAX_CMDLINE_LEN - 2)) < 0) {}
+ if (in_buf[num - 1] == '\n') {
+ in_buf[num - 1] = 0;
+ }
- ret[rc] = ptr;
+ char delim = ' ';
+ char *curarg = strtok(ptr, &delim);
+ while (curarg && rc < MAX_CMDLINE_PAR) {
+ ret[rc] = curarg;
if (ret[rc][0] == 0x02 && !ret[rc][1]) ret[rc]++;
rc++;
-
- while (*ptr)
- ptr++;
- ptr++;
-
+ curarg = strtok(NULL, &delim);
}
*argc = rc;
-
return ret;
}
@@ -87,4 +88,3 @@ static char **afl_init_argv(int *argc) {
#undef MAX_CMDLINE_PAR
#endif /* !_HAVE_ARGV_FUZZ_INL */
-
