summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--payloads/libpayload/libc/string.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/payloads/libpayload/libc/string.c b/payloads/libpayload/libc/string.c
index 99857493c0..a58efde135 100644
--- a/payloads/libpayload/libc/string.c
+++ b/payloads/libpayload/libc/string.c
@@ -609,11 +609,15 @@ char* strtok_r(char *str, const char *delim, char **ptr)
/* skip over prefix delimiters */
char *start = str + strspn(str, delim);
+ if (start[0] == '\0')
+ return NULL;
+
/* find first delimiter character */
char *end = start + strcspn(start, delim);
- end[0] = '\0';
+ *ptr = end;
+ if (end[0] != '\0')
+ *(*ptr)++ = '\0';
- *ptr = end+1;
return start;
}