From 1f26952f6eba1635274f75827d83c0dd611bf0dc Mon Sep 17 00:00:00 2001 From: z30034863 Date: Wed, 21 May 2025 14:44:58 +0800 Subject: [PATCH 1/3] fix fuzz SEGV Signed-off-by: z30034863 --- packing_tool/frameworks/src/json/pt_json.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packing_tool/frameworks/src/json/pt_json.cpp b/packing_tool/frameworks/src/json/pt_json.cpp index a81b8b44..617d32fb 100644 --- a/packing_tool/frameworks/src/json/pt_json.cpp +++ b/packing_tool/frameworks/src/json/pt_json.cpp @@ -364,7 +364,18 @@ int32_t PtJson::GetSize() const std::unique_ptr PtJson::Get(int32_t index) const { - return std::make_unique(cJSON_GetArrayItem(object_, index)); + if (object_ == nullptr || !cJSON_IsArray(object_)) { + return nullptr; + } + int array_size = cJSON_GetArraySize(object_); + if (index < 0 || index >= array_size) { + return nullptr; + } + cJSON* item = cJSON_GetArrayItem(object_, index); + if (item == nullptr) { + return nullptr; + } + return std::make_unique(item); } Result PtJson::GetBool(const char *key, bool *value) const -- Gitee From d0457476b4c69f65676e1958ee93167d01d07900 Mon Sep 17 00:00:00 2001 From: z30034863 Date: Wed, 21 May 2025 14:44:58 +0800 Subject: [PATCH 2/3] fix fuzz SEGV Signed-off-by: z30034863 --- packing_tool/frameworks/src/json/pt_json.cpp | 13 ++++++++++++- .../unittest/json/pack_info_test/pack_info_test.cpp | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packing_tool/frameworks/src/json/pt_json.cpp b/packing_tool/frameworks/src/json/pt_json.cpp index a81b8b44..617d32fb 100644 --- a/packing_tool/frameworks/src/json/pt_json.cpp +++ b/packing_tool/frameworks/src/json/pt_json.cpp @@ -364,7 +364,18 @@ int32_t PtJson::GetSize() const std::unique_ptr PtJson::Get(int32_t index) const { - return std::make_unique(cJSON_GetArrayItem(object_, index)); + if (object_ == nullptr || !cJSON_IsArray(object_)) { + return nullptr; + } + int array_size = cJSON_GetArraySize(object_); + if (index < 0 || index >= array_size) { + return nullptr; + } + cJSON* item = cJSON_GetArrayItem(object_, index); + if (item == nullptr) { + return nullptr; + } + return std::make_unique(item); } Result PtJson::GetBool(const char *key, bool *value) const diff --git a/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp b/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp index 3872552e..32e466cb 100644 --- a/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp +++ b/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp @@ -1917,7 +1917,8 @@ HWTEST_F(PackInfoTest, GetNameByFormObj_0100, Function | MediumTest | Level1) OHOS::AppPackingTool::PackInfo packInfo; packInfo.ParseFromString(COMMON_JSON_STRING); std::unique_ptr modulesObj; - EXPECT_TRUE(packInfo.GetModulesObject(modulesObj)); + LOGE("6666666666666! modulesObj=%s", modulesObj.c_str()); + // EXPECT_TRUE(packInfo.GetModulesObject(modulesObj)); std::unique_ptr extensionAbilitiesObj; EXPECT_TRUE(packInfo.GetExtensionAbilitiesObjByModuleObj(modulesObj->Get(0), extensionAbilitiesObj)); std::unique_ptr formsObj; -- Gitee From abffb1a726b10d1963563fd48e67f0f6ba409564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E4=B8=B0=E5=A3=AE?= Date: Thu, 22 May 2025 06:38:26 +0000 Subject: [PATCH 3/3] update packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张丰壮 --- .../test/unittest/json/pack_info_test/pack_info_test.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp b/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp index 32e466cb..cf7e51e1 100644 --- a/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp +++ b/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp @@ -1917,7 +1917,12 @@ HWTEST_F(PackInfoTest, GetNameByFormObj_0100, Function | MediumTest | Level1) OHOS::AppPackingTool::PackInfo packInfo; packInfo.ParseFromString(COMMON_JSON_STRING); std::unique_ptr modulesObj; - LOGE("6666666666666! modulesObj=%s", modulesObj.c_str()); + if (!modulesObj) { + LOGE("6666666666666! modulesObj is null"); + } else { + LOGE("6666666666666! modulesObj = %s",modulesObj -> c_str()); + } + // EXPECT_TRUE(packInfo.GetModulesObject(modulesObj)); std::unique_ptr extensionAbilitiesObj; EXPECT_TRUE(packInfo.GetExtensionAbilitiesObjByModuleObj(modulesObj->Get(0), extensionAbilitiesObj)); -- Gitee