mirror of
https://github.com/weechat/weechat.git
synced 2026-06-30 14:56:39 +02:00
core: ensure length is not negative in function string_strndup
This commit is contained in:
@@ -76,7 +76,7 @@ string_strndup (const char *string, int length)
|
||||
{
|
||||
char *result;
|
||||
|
||||
if (!string)
|
||||
if (!string || (length < 0))
|
||||
return NULL;
|
||||
|
||||
if ((int)strlen (string) < length)
|
||||
|
||||
@@ -123,6 +123,8 @@ TEST(String, Duplicate)
|
||||
|
||||
POINTERS_EQUAL(NULL, string_strndup (NULL, 0));
|
||||
|
||||
POINTERS_EQUAL(NULL, string_strndup (str_test, -1));
|
||||
|
||||
str = string_strndup (str_test, 0);
|
||||
CHECK(str);
|
||||
CHECK(str != str_test);
|
||||
|
||||
Reference in New Issue
Block a user