2764: Prevent NULL pointer in mem_copy (fixes #2753) r=heinrich5991 a=Jupeyy



Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
bors[bot] 2020-09-06 22:42:29 +00:00 committed by GitHub
commit 297f2764f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -3223,8 +3223,11 @@ const char *str_next_token(const char *str, const char *delim, char *buffer, int
{ {
int len = 0; int len = 0;
const char *tok = str_token_get(str, delim, &len); const char *tok = str_token_get(str, delim, &len);
if(len < 0) if(len < 0 || tok == NULL)
{
buffer[0] = '\0';
return NULL; return NULL;
}
len = buffer_size > len ? len : buffer_size - 1; len = buffer_size > len ? len : buffer_size - 1;
mem_copy(buffer, tok, len); mem_copy(buffer, tok, len);

View file

@ -173,6 +173,7 @@ TEST(Str, InList)
EXPECT_FALSE(str_in_list("", ",", "xyz")); EXPECT_FALSE(str_in_list("", ",", "xyz"));
EXPECT_TRUE(str_in_list("FOO,,BAR", ",", "")); EXPECT_TRUE(str_in_list("FOO,,BAR", ",", ""));
EXPECT_TRUE(str_in_list("abc,,def", ",", "def"));
} }
TEST(Str, StrFormat) TEST(Str, StrFormat)