mirror of
https://github.com/DaveGamble/cJSON.git
synced 2026-10-17 10:49:50 +00:00
allocate memory for the temporary buffer
Allocate memory for the temporary buffer when paring numbers. This fixes CVE-2023-26819
This commit is contained in:
1 parent
12c4bf1986
commit
a328d65ad4
3 files changed
+69
-5
No files matched your search
@@ -48,6 +48,7 @@ static void assert_parse_number(const char *string, int integer, double real)
|
||||
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
|
||||
buffer.content = (const unsigned char*)string;
|
||||
buffer.length = strlen(string) + sizeof("");
|
||||
buffer.hooks = global_hooks;
|
||||
|
||||
TEST_ASSERT_TRUE(parse_number(item, &buffer));
|
||||
assert_is_number(item);
|
||||
@@ -55,6 +56,17 @@ static void assert_parse_number(const char *string, int integer, double real)
|
||||
TEST_ASSERT_EQUAL_DOUBLE(real, item->valuedouble);
|
||||
}
|
||||
|
||||
static void assert_parse_big_number(const char *string)
|
||||
{
|
||||
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
|
||||
buffer.content = (const unsigned char*)string;
|
||||
buffer.length = strlen(string) + sizeof("");
|
||||
buffer.hooks = global_hooks;
|
||||
|
||||
TEST_ASSERT_TRUE(parse_number(item, &buffer));
|
||||
assert_is_number(item);
|
||||
}
|
||||
|
||||
static void parse_number_should_parse_zero(void)
|
||||
{
|
||||
assert_parse_number("0", 0, 0);
|
||||
@@ -96,6 +108,13 @@ static void parse_number_should_parse_negative_reals(void)
|
||||
assert_parse_number("-123e-128", 0, -123e-128);
|
||||
}
|
||||
|
||||
static void parse_number_should_parse_big_numbers(void)
|
||||
{
|
||||
assert_parse_big_number("9999999999999999999999999999999999999999999999912345678901234567");
|
||||
assert_parse_big_number("9999999999999999999999999999999999999999999999912345678901234567E10");
|
||||
assert_parse_big_number("999999999999999999999999999999999999999999999991234567890.1234567");
|
||||
}
|
||||
|
||||
int CJSON_CDECL main(void)
|
||||
{
|
||||
/* initialize cJSON item */
|
||||
@@ -106,5 +125,6 @@ int CJSON_CDECL main(void)
|
||||
RUN_TEST(parse_number_should_parse_positive_integers);
|
||||
RUN_TEST(parse_number_should_parse_positive_reals);
|
||||
RUN_TEST(parse_number_should_parse_negative_reals);
|
||||
RUN_TEST(parse_number_should_parse_big_numbers);
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in new issue
Block a user