mirror of
https://github.com/openharmony/third_party_cJSON.git
synced 2026-07-01 02:47:21 -04:00
!118 merge master into master
合入社区修改:fix: prevent NULL pointer dereference in cJSON_SetNumberHelper (#991) Created-by: mohaoyuan Commit-by: mohaoyuan Merged-by: openharmony_ci Description: ### 相关的Issue https://gitcode.com/openharmony/third_party_cJSON/issues/91 ### 原因(目的、解决的问题等) 合入社区修改:fix: prevent NULL pointer dereference in cJSON_SetNumberHelper (#991) ### 描述(做了什么,变更了什么) 合入社区修改:fix: prevent NULL pointer dereference in cJSON_SetNumberHelper (#991) ### 测试用例(新增、改动、可能影响的功能) See merge request: openharmony/third_party_cJSON!118
This commit is contained in:
@@ -414,6 +414,11 @@ loop_end:
|
||||
/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */
|
||||
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number)
|
||||
{
|
||||
if (object == NULL)
|
||||
{
|
||||
return (double)NAN;
|
||||
}
|
||||
|
||||
if (number >= INT_MAX)
|
||||
{
|
||||
object->valueint = INT_MAX;
|
||||
|
||||
+3
-2
@@ -27,6 +27,7 @@
|
||||
#include "unity/examples/unity_config.h"
|
||||
#include "unity/src/unity.h"
|
||||
#include "common.h"
|
||||
#include <math.h>
|
||||
|
||||
static void cjson_array_foreach_should_loop_over_arrays(void)
|
||||
{
|
||||
@@ -478,8 +479,8 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
|
||||
TEST_ASSERT_NULL(cJSON_SetValuestring(corruptedString, "test"));
|
||||
TEST_ASSERT_NULL(cJSON_SetValuestring(item, NULL));
|
||||
cJSON_Minify(NULL);
|
||||
/* skipped because it is only used via a macro that checks for NULL */
|
||||
/* cJSON_SetNumberHelper(NULL, 0); */
|
||||
/* cJSON_SetNumberHelper should handle NULL gracefully */
|
||||
TEST_ASSERT_TRUE(isnan(cJSON_SetNumberHelper(NULL, 0)));
|
||||
|
||||
/* restore corrupted item2 to delete it */
|
||||
item2->prev = originalPrev;
|
||||
|
||||
Reference in New Issue
Block a user