From 4b214e112cdee2579b19f0cde8feb575dad1d6b0 Mon Sep 17 00:00:00 2001 From: luming Date: Wed, 31 Jul 2024 14:54:35 +0800 Subject: [PATCH] [Bug] Fix memory leak risk in syscap_tool IssueNo: https://gitee.com/openharmony/developtools_syscap_codec/issues/IAGOX4 Signed-off-by: luming --- src/create_pcid.c | 7 ++++++- src/main.c | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/create_pcid.c b/src/create_pcid.c index 64814f3..4972ac9 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -112,7 +112,12 @@ int32_t SetPriSyscap(PCIDMain *pcidBuffer, cJSON *jsonPriSyscapObj, PRINT_ERR("get jsonArrayItem failed!"); return -1; } - priSyscapStr = strchr(jsonArrayItem->valuestring, '.') + 1; + priSyscapStr = strchr(jsonArrayItem->valuestring, '.'); + if (priSyscapStr == NULL) { + PRINT_ERR("get priSyscapStr failed!"); + return -1; + } + priSyscapStr += 1; errno_t nRet = strcat_s(priSyscapHead, allPriSyscapStrLen + 1, priSyscapStr); nRet += strcat_s(priSyscapHead, allPriSyscapStrLen + 1, ","); if (nRet != EOK) { diff --git a/src/main.c b/src/main.c index 14879e3..2fd051a 100644 --- a/src/main.c +++ b/src/main.c @@ -78,6 +78,10 @@ int main(int argc, char **argv) g_customerfileinfo.pcidfile = NULL; g_customerfileinfo.rpcidfile = NULL; char *outputpath = getcwd(curpath, sizeof(curpath)); + if (outputpath == NULL) { + PRINT_ERR("Get outputpath failed.\n"); + return -1; + } while (1) { int32_t flag = getopt_long(argc, argv, "hvRPC:edsi:o:", g_longOptions, &optIndex); -- Gitee