From ae2d4a28f08f02df3da67614497842059704c21b Mon Sep 17 00:00:00 2001 From: zhaohang Date: Wed, 18 Sep 2024 10:28:22 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8D=A2=E4=B8=80=E7=A7=8D=E6=94=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaohang --- interfaces/inner_api/syscap_interface.c | 5 +++++ src/main.c | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 0580c69..ffaec32 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -625,6 +625,11 @@ static int32_t ComparePcidWithPriSyscap(struct PcidPriSyscapInfo pcidPriSyscapIn free(temp); return -1; } + if (pcidPriSyscapInfo.ossyscapFlag + prisyscapFlag >= MAX_MISS_SYSCAP) + { + PRINT_ERR("array index out of bounds.\n"); + return -1; + } result->syscap[pcidPriSyscapInfo.ossyscapFlag + prisyscapFlag] = temp; ++prisyscapFlag; } diff --git a/src/main.c b/src/main.c index 2fd051a..be00763 100644 --- a/src/main.c +++ b/src/main.c @@ -74,9 +74,9 @@ int main(int argc, char **argv) int32_t ret; uint16_t bitMap = 0x0; char curpath[PATH_MAX] = {0}; - g_customerfileinfo.inputfile = NULL; - g_customerfileinfo.pcidfile = NULL; - g_customerfileinfo.rpcidfile = NULL; + g_customerfileinfo.inputfile = ""; + g_customerfileinfo.pcidfile = ""; + g_customerfileinfo.rpcidfile = ""; char *outputpath = getcwd(curpath, sizeof(curpath)); if (outputpath == NULL) { PRINT_ERR("Get outputpath failed.\n"); -- Gitee From d24498bced0b9fd4855c810030a01a7cc727b3cb Mon Sep 17 00:00:00 2001 From: zhaohang Date: Wed, 18 Sep 2024 13:55:09 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=BF=AE=E6=94=B9=20Sign?= =?UTF-8?q?ed-off-by:=20zhaohang=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaohang --- interfaces/inner_api/syscap_interface.c | 5 +++-- src/create_pcid.c | 22 +++++++++++++++++++++- src/main.c | 6 +++--- src/syscap_tool.c | 20 ++++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index ffaec32..7a8442e 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -625,9 +625,10 @@ static int32_t ComparePcidWithPriSyscap(struct PcidPriSyscapInfo pcidPriSyscapIn free(temp); return -1; } - if (pcidPriSyscapInfo.ossyscapFlag + prisyscapFlag >= MAX_MISS_SYSCAP) - { + if (pcidPriSyscapInfo.ossyscapFlag + prisyscapFlag >= MAX_MISS_SYSCAP) { + FreeCompareError(result); PRINT_ERR("array index out of bounds.\n"); + free(temp); return -1; } result->syscap[pcidPriSyscapInfo.ossyscapFlag + prisyscapFlag] = temp; diff --git a/src/create_pcid.c b/src/create_pcid.c index 7b99567..ba4b838 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -249,8 +249,13 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) uint32_t privateCapSize, osCapSize; uint32_t contextBufLen; char *contextBuffer = NULL; - cJSON *allOsSyscapObj = CreateWholeSyscapJsonObj(); + if (inputFile == NULL) { + PRINT_ERR("inputFile is null.\n"); + return -1; + } + + cJSON *allOsSyscapObj = CreateWholeSyscapJsonObj(); int32_t ret = GetFileContext(inputFile, &contextBuffer, (uint32_t *)&contextBufLen); if (ret != 0) { PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); @@ -482,6 +487,11 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) freePcidJsonInfo.sysCapObj = NULL; freePcidJsonInfo.flag = 0; + if (inputFile == NULL) { + PRINT_ERR("inputFile is null.\n"); + return -1; + } + ret = GetFileContext(inputFile, &freePcidJsonInfo.contextBuffer, (uint32_t *)&contextBufLen); if (ret != 0) { PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); @@ -693,6 +703,10 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt static int32_t GetSyscapStr(char *input, char const *priSyscapStr, uint32_t* osSyscap, uint32_t *pcidHeader) { + if (input == NULL) { + PRINT_ERR("inputFile is null.\n"); + return -1; + } char *ctx = NULL; uint32_t fileContextLen; if (GetFileContext(input, &ctx, (uint32_t *)&fileContextLen) != 0) { @@ -715,6 +729,7 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) uint32_t pcidHeader[PCID_HEADER]; char *priSyscapStr = NULL; char *jsonBuffer = NULL; + ret = GetSyscapStr(input, priSyscapStr, osSyscap, pcidHeader); if (ret == -1) { return ret; @@ -872,6 +887,11 @@ int32_t EncodePcidscToString(char *inputFile, char *outDirPath) freePcidInfo.outDirPathFinal = outDirPath; PCIDMain *pcidMain = NULL; + if (inputFile == NULL) { + PRINT_ERR("inputFile is null.\n"); + return -1; + } + ret = GetFileContext(inputFile, &freePcidInfo.contextBuffer, (uint32_t *)&bufferLen); if (ret != 0) { PRINT_ERR("Get pcid file failed, pcid file path: %s\n", inputFile); diff --git a/src/main.c b/src/main.c index be00763..2fd051a 100644 --- a/src/main.c +++ b/src/main.c @@ -74,9 +74,9 @@ int main(int argc, char **argv) int32_t ret; uint16_t bitMap = 0x0; char curpath[PATH_MAX] = {0}; - g_customerfileinfo.inputfile = ""; - g_customerfileinfo.pcidfile = ""; - g_customerfileinfo.rpcidfile = ""; + g_customerfileinfo.inputfile = NULL; + g_customerfileinfo.pcidfile = NULL; + g_customerfileinfo.rpcidfile = NULL; char *outputpath = getcwd(curpath, sizeof(curpath)); if (outputpath == NULL) { PRINT_ERR("Get outputpath failed.\n"); diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 4ff330a..2b08974 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -150,6 +150,11 @@ int32_t RPCIDEncode(char *inputFile, char *outputPath) gJsonObjectSysCap.cjsonObjectRoot = NULL; gJsonObjectSysCap.sysCapPtr = NULL; + if (inputFile == NULL) { + PRINT_ERR("inputFile is null.\n"); + return -1; + } + if (GetFileContext(inputFile, &contextBuffer, &bufferLen) != 0) { PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); return -1; @@ -262,6 +267,11 @@ int32_t RPCIDDecode(char *inputFile, char *outputPath) char *convertedBuffer = NULL; uint32_t bufferLen; + if (inputFile == NULL) { + PRINT_ERR("inputFile is null.\n"); + return -1; + } + // check rpcid.sc if (CheckRpcidFormat(inputFile, &contextBuffer, &bufferLen)) { PRINT_ERR("Check rpcid.sc format failed. Input failed: %s\n", inputFile); @@ -480,6 +490,11 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath) freeAfterEncodeRpcidscInfo.type = 0; freeAfterEncodeRpcidscInfo.flag = 0; + if (inputFile == NULL) { + PRINT_ERR("inputFile is null.\n"); + return -1; + } + // check rpcid.sc if (CheckRpcidFormat(inputFile, &freeAfterEncodeRpcidscInfo.contextBuffer, &bufferLen) != 0) { PRINT_ERR("Check rpcid.sc format failed. Input file: %s\n", inputFile); @@ -699,6 +714,11 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t typ uint32_t pcidOsArray[PCID_OUT_BUFFER] = {0}; uint32_t rpcidOsAarry[PCID_OUT_BUFFER] = {0}; + if (pcidFile == NULL || rpcidFile == NULL) { + PRINT_ERR("pcidFile or rpcidFile is null.\n"); + return -1; + } + if (type == TYPE_FILE) { if (GetFileContext(pcidFile, &pcidContent, &pcidContentLen)) { PRINT_ERR("Get pcid file context failed, input file : %s\n", pcidFile); -- Gitee From de301589860baf11a6e1a16f6ada792335982693 Mon Sep 17 00:00:00 2001 From: zhaohang Date: Thu, 19 Sep 2024 16:50:39 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=B6=85=E9=95=BF?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaohang --- include/context_tool.h | 1 + src/context_tool.c | 13 +++++++++++++ src/create_pcid.c | 24 +++--------------------- src/syscap_tool.c | 8 +------- 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/include/context_tool.h b/include/context_tool.h index b8b437a..2160be7 100644 --- a/include/context_tool.h +++ b/include/context_tool.h @@ -40,6 +40,7 @@ typedef struct RequiredProductCompatibilityIDHead { void FreeContextBuffer(char *contextBuffer); int32_t GetFileContext(const char *inputFile, char **contextBufPtr, uint32_t *bufferLen); +int32_t CheckFileAndGetFileContext(const char *inputFile, char **contextBufPtr, uint32_t *bufferLen); int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename, char *convertedBuffer, size_t contextBufLen); int32_t CheckRpcidFormat(const char *inputFile, char **buffer, uint32_t *len); cJSON *CreateWholeSyscapJsonObj(void); diff --git a/src/context_tool.c b/src/context_tool.c index ea5359f..e75f853 100644 --- a/src/context_tool.c +++ b/src/context_tool.c @@ -92,6 +92,19 @@ int32_t GetFileContext(const char *inputFile, char **contextBufPtr, uint32_t *bu return 0; } +int32_t CheckFileAndGetFileContext(const char *inputFile, char **contextBufPtr, uint32_t *bufferLen) +{ + if (inputFile == NULL) { + PRINT_ERR("input file is NULL.\n"); + return -1; + } + uint32_t ret = GetFileContext(inputFile, contextBufPtr, bufferLen); + if (ret != 0) { + PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); + } + return ret; +} + int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename, char *convertedBuffer, size_t contextBufLen) { int32_t ret; diff --git a/src/create_pcid.c b/src/create_pcid.c index ba4b838..5a8a327 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -250,15 +250,9 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) uint32_t contextBufLen; char *contextBuffer = NULL; - if (inputFile == NULL) { - PRINT_ERR("inputFile is null.\n"); - return -1; - } - cJSON *allOsSyscapObj = CreateWholeSyscapJsonObj(); - int32_t ret = GetFileContext(inputFile, &contextBuffer, (uint32_t *)&contextBufLen); + int32_t ret = CheckFileAndGetFileContext(inputFile, &contextBuffer, (uint32_t *)&contextBufLen); if (ret != 0) { - PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, -1); } @@ -486,15 +480,9 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) freePcidJsonInfo.jsonRootObj = NULL; freePcidJsonInfo.sysCapObj = NULL; freePcidJsonInfo.flag = 0; - - if (inputFile == NULL) { - PRINT_ERR("inputFile is null.\n"); - return -1; - } - ret = GetFileContext(inputFile, &freePcidJsonInfo.contextBuffer, (uint32_t *)&contextBufLen); + ret = CheckFileAndGetFileContext(inputFile, &freePcidJsonInfo.contextBuffer, (uint32_t *)&contextBufLen); if (ret != 0) { - PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); return -1; } @@ -887,14 +875,8 @@ int32_t EncodePcidscToString(char *inputFile, char *outDirPath) freePcidInfo.outDirPathFinal = outDirPath; PCIDMain *pcidMain = NULL; - if (inputFile == NULL) { - PRINT_ERR("inputFile is null.\n"); - return -1; - } - - ret = GetFileContext(inputFile, &freePcidInfo.contextBuffer, (uint32_t *)&bufferLen); + ret = CheckFileAndGetFileContext(inputFile, &freePcidInfo.contextBuffer, (uint32_t *)&bufferLen); if (ret != 0) { - PRINT_ERR("Get pcid file failed, pcid file path: %s\n", inputFile); return -1; } diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 2b08974..d58259b 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -150,13 +150,7 @@ int32_t RPCIDEncode(char *inputFile, char *outputPath) gJsonObjectSysCap.cjsonObjectRoot = NULL; gJsonObjectSysCap.sysCapPtr = NULL; - if (inputFile == NULL) { - PRINT_ERR("inputFile is null.\n"); - return -1; - } - - if (GetFileContext(inputFile, &contextBuffer, &bufferLen) != 0) { - PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); + if (CheckFileAndGetFileContext(inputFile, &contextBuffer, &bufferLen) != 0) { return -1; } -- Gitee