From 1f26952f6eba1635274f75827d83c0dd611bf0dc Mon Sep 17 00:00:00 2001 From: z30034863 Date: Wed, 21 May 2025 14:44:58 +0800 Subject: [PATCH 1/6] 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/6] 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/6] 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 From fe44540c3cd9220d55a7f48d984058e24c4c6494 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 4/6] 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 | 8 +++++++- 1 file changed, 7 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..d7786b29 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 @@ -21,6 +21,7 @@ #define protected public #include "pack_info.h" #include "pt_json.h" +#include "log.h" #undef private #undef protected @@ -1917,7 +1918,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 From 911fedee3ef9c04046178d44fbd32d6878e82367 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 09:03:00 +0000 Subject: [PATCH 5/6] 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 | 2 +- 1 file changed, 1 insertion(+), 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 d7786b29..5081a03e 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 @@ -1921,7 +1921,7 @@ HWTEST_F(PackInfoTest, GetNameByFormObj_0100, Function | MediumTest | Level1) if (!modulesObj) { LOGE("6666666666666! modulesObj is null"); } else { - LOGE("6666666666666! modulesObj = %s",modulesObj -> c_str()); + LOGE("6666666666666! modulesObj not null"); } // EXPECT_TRUE(packInfo.GetModulesObject(modulesObj)); -- Gitee From 1110ce75f5a5f116f9c8b704703976f9dc37b703 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 09:16:07 +0000 Subject: [PATCH 6/6] 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: 张丰壮 --- .../unittest/json/pack_info_test/pack_info_test.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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 5081a03e..2c33ba00 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 @@ -21,7 +21,6 @@ #define protected public #include "pack_info.h" #include "pt_json.h" -#include "log.h" #undef private #undef protected @@ -1918,12 +1917,11 @@ HWTEST_F(PackInfoTest, GetNameByFormObj_0100, Function | MediumTest | Level1) OHOS::AppPackingTool::PackInfo packInfo; packInfo.ParseFromString(COMMON_JSON_STRING); std::unique_ptr modulesObj; - if (!modulesObj) { - LOGE("6666666666666! modulesObj is null"); - } else { - LOGE("6666666666666! modulesObj not null"); - } - + // if (!modulesObj) { + // LOGE("6666666666666! modulesObj is null"); + // } else { + // LOGE("6666666666666! modulesObj not null"); + // } // EXPECT_TRUE(packInfo.GetModulesObject(modulesObj)); std::unique_ptr extensionAbilitiesObj; EXPECT_TRUE(packInfo.GetExtensionAbilitiesObjByModuleObj(modulesObj->Get(0), extensionAbilitiesObj)); -- Gitee