1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:34:59 +00:00

LibC: Set saved_str to null in strtok_r if no tokens were found

If we do not do this, the next call to strtok_r will start tokenizing
(and possibly modifying!) the memory pointed to by `saved_ptr`.
This commit is contained in:
Daniel Bertalan 2022-02-26 12:53:02 +01:00 committed by Linus Groh
parent 4b4177f39c
commit ea52ba9fdc
2 changed files with 17 additions and 2 deletions

View file

@ -375,7 +375,7 @@ char* strpbrk(const char* s, const char* accept)
char* strtok_r(char* str, const char* delim, char** saved_str)
{
if (!str) {
if (!saved_str)
if (!saved_str || *saved_str == nullptr)
return nullptr;
str = *saved_str;
}
@ -407,8 +407,10 @@ char* strtok_r(char* str, const char* delim, char** saved_str)
}
}
if (str[token_start] == '\0')
if (str[token_start] == '\0') {
*saved_str = nullptr;
return nullptr;
}
if (token_end == 0) {
*saved_str = nullptr;