diff --git a/BUILD.gn b/BUILD.gn index f38e04bbecd5704d82baf33786eb60b08e6ced84..630ec5883ce355e987d43b5e3048481d02f3a709 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -34,7 +34,6 @@ ohos_executable("syscap_tool_bin") { if (is_mingw) { defines += [ "_POSIX_" ] } - sources = [ "./src/main.c" ] sources += sources_platform_common diff --git a/include/syscap_define.h b/include/syscap_define.h index 24b2e73c26bdf601df254cb53a67e80fa456cda7..5e47afcb33519bac0f0ff494f87dafcd2a24f03d 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -280,7 +280,7 @@ static SyscapWithNum arraySyscap[] = { {"SystemCapability.Security.DeviceAuth", SECURITY_DEVICEAUTH}, {"SystemCapability.Security.DeviceSecurityLevel", SECURITY_DEVICESECURITYLEVEL}, {"SystemCapability.Security.Huks", SECURITY_HUKS}, - {"SystemCapability.Sensors.Medical_sensor", SENSORS_MEDICAL_SENSOR}, + {"SystemCapability.Sensors.Medical.Sensor", SENSORS_MEDICAL_SENSOR}, {"SystemCapability.Sensors.MiscDevice", SENSORS_MISCDEVICE}, {"SystemCapability.Sensors.Sensor", SENSORS_SENSOR}, {"SystemCapability.Sensors.Sensor.Lite", SENSORS_SENSOR_LITE}, @@ -305,4 +305,4 @@ static SyscapWithNum arraySyscap[] = { {"SystemCapability.UserIAM.UserIdm", USERIAM_USERIDM} }; -#endif // _SYSCAP_DEFINE_H \ No newline at end of file +#endif // _SYSCAP_DEFINE_H diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index d53dcc2c8d3ec66cb8f64d00476bd2fb666c1652..d96f95e91e6791e2b02c02ff2a47b4231e3c441c 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -25,10 +25,10 @@ #include "syscap_interface.h" #define PCID_OUT_BUFFER 32 -#define MAX_SYSCAP_STR_LEN 128 #define OS_SYSCAP_BYTES 120 #define BITS_OF_BYTE 8 #define PCID_MAIN_LEN 128 +#define PATH_MAX 4096 #define PRINT_ERR(...) \ do { \ @@ -36,19 +36,19 @@ printf(__VA_ARGS__); \ } while (0) -static char *inputFile = "/system/etc/PCID.sc"; - static void FreeContextBuffer(char *contextBuffer) { (void)free(contextBuffer); } -static uint32_t GetFileContext(char **contextBufPtr, uint32_t *bufferLen) +static int32_t GetFileContext(char **contextBufPtr, uint32_t *bufferLen) { - uint32_t ret; + int32_t ret; FILE *fp = NULL; struct stat statBuf; char *contextBuffer = NULL; + const char *inputFile = "/system/etc/PCID.sc"; + ret = stat(inputFile, &statBuf); if (ret != 0) { PRINT_ERR("get file(%s) st_mode failed, errno = %d\n", inputFile, errno); @@ -63,6 +63,7 @@ static uint32_t GetFileContext(char **contextBufPtr, uint32_t *bufferLen) PRINT_ERR("malloc buffer failed, size = %d, errno = %d\n", (int32_t)statBuf.st_size + 1, errno); return -1; } + fp = fopen(inputFile, "rb"); if (fp == NULL) { PRINT_ERR("open file(%s) failed, errno = %d\n", inputFile, errno); @@ -84,7 +85,7 @@ static uint32_t GetFileContext(char **contextBufPtr, uint32_t *bufferLen) return 0; } -bool EncodeOsSyscap(char output[128]) +bool EncodeOsSyscap(char output[MAX_SYSCAP_STR_LEN]) { int32_t ret; int32_t res; @@ -130,7 +131,7 @@ bool EncodePrivateSyscap(char **output, int *outputLen) } (void)memset_s(outputStr, *outputLen, 0, *outputLen); - ret = strncpy_s(outputStr, *outputLen, contextBuffer + PCID_MAIN_LEN, *outputLen); + ret = strncpy_s(outputStr, *outputLen, contextBuffer + PCID_MAIN_LEN, *outputLen - 1); if (ret != 0) { PRINT_ERR("strcpy_s failed."); FreeContextBuffer(contextBuffer); @@ -197,8 +198,7 @@ bool DecodePrivateSyscap(char *input, char (**output)[128], int *outputCnt) { char (*outputArray)[MAX_SYSCAP_STR_LEN] = NULL; char *inputPos = input; - uint16_t bufferLen; - int ret; + int bufferLen, ret; int syscapCnt = 0; while (*inputPos != '\0') { diff --git a/interfaces/inner_api/syscap_interface.h b/interfaces/inner_api/syscap_interface.h index 1336887f09e4c1b004066cdefb759ff979bba99b..a225479690451556cf531a189cb8a9d32f33bbe8 100644 --- a/interfaces/inner_api/syscap_interface.h +++ b/interfaces/inner_api/syscap_interface.h @@ -25,7 +25,9 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ -bool EncodeOsSyscap(char output[128]); +#define MAX_SYSCAP_STR_LEN 128 + +bool EncodeOsSyscap(char output[MAX_SYSCAP_STR_LEN]); bool DecodeOsSyscap(char input[128], char (**output)[128], int *outputCnt); bool EncodePrivateSyscap(char **output, int *outputLen); bool DecodePrivateSyscap(char *input, char (**output)[128], int *outputCnt); diff --git a/napi/napi_query_syscap.cpp b/napi/napi_query_syscap.cpp index bb403ffbf6eab6e518456d74e439439f667653c8..2ff3fb1a3fa844947fe3bce514238e83f2ca06d2 100644 --- a/napi/napi_query_syscap.cpp +++ b/napi/napi_query_syscap.cpp @@ -61,7 +61,7 @@ static char* getSystemCapability() bool retBool; int retError, priOutputLen, priCapArrayCnt, sumLen; int i = 0; - char osOutput[128] = {}; + char osOutput[SYSCAP_STR_MAX_LEN] = {}; errno_t err = EOK; uint32_t *osCapU32 = nullptr; char *priOutput = nullptr; diff --git a/src/create_pcid.c b/src/create_pcid.c index dc7d1dc46b24e1841ec8ca478e4bdb0529a332f0..efd478cae0247c6c965bd10c1b9518f0a2b9fcc8 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -47,20 +47,33 @@ static void FreeContextBuffer(char *contextBuffer) (void)free(contextBuffer); } -static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *contextBufLen) +static int32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *contextBufLen) { - uint32_t ret; + int32_t ret; FILE *fp = NULL; struct stat statBuf; char *contextBuffer = NULL; + char path[PATH_MAX + 1] = {0x00}; - ret = stat(inputFile, &statBuf); +#ifdef _POSIX_ + if (strlen(inputFile) > PATH_MAX || strncpy_s(path, PATH_MAX, inputFile, strlen(inputFile)) != EOK) { + PRINT_ERR("get path(%s) failed\n", inputFile); + return -1; + } +#else + if (strlen(inputFile) > PATH_MAX || realpath(inputFile, path) == NULL) { + PRINT_ERR("get file(%s) real path failed\n", inputFile); + return -1; + } +#endif + + ret = stat(path, &statBuf); if (ret != 0) { - PRINT_ERR("get file(%s) st_mode failed, errno = %d\n", inputFile, errno); + PRINT_ERR("get file(%s) st_mode failed, errno = %d\n", path, errno); return -1; } if (!(statBuf.st_mode & S_IRUSR)) { - PRINT_ERR("don't have permission to read the file(%s)\n", inputFile); + PRINT_ERR("don't have permission to read the file(%s)\n", path); return -1; } contextBuffer = (char *)malloc(statBuf.st_size + 1); @@ -68,15 +81,16 @@ static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t * PRINT_ERR("malloc buffer failed, size = %d, errno = %d\n", (int32_t)statBuf.st_size + 1, errno); return -1; } - fp = fopen(inputFile, "rb"); + + fp = fopen(path, "rb"); if (fp == NULL) { - PRINT_ERR("open file(%s) failed, errno = %d\n", inputFile, errno); + PRINT_ERR("open file(%s) failed, errno = %d\n", path, errno); FreeContextBuffer(contextBuffer); return -1; } ret = fread(contextBuffer, statBuf.st_size, 1, fp); if (ret != 1) { - PRINT_ERR("read file(%s) failed, errno = %d\n", inputFile, errno); + PRINT_ERR("read file(%s) failed, errno = %d\n", path, errno); FreeContextBuffer(contextBuffer); (void)fclose(fp); return -1; @@ -94,35 +108,44 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename { int32_t ret; FILE *fp = NULL; - char fileFullPath[PATH_MAX] = {0}; int32_t pathLen = strlen(outDirPath); + char path[PATH_MAX + 1] = {0x00}; - ret = strncpy_s(fileFullPath, PATH_MAX, outDirPath, pathLen + 1); - if (ret != 0) { - PRINT_ERR("strncpy_s failed, source string:%s, len = %d, errno = %d\n", outDirPath, pathLen + 1, errno); +#ifdef _POSIX_ + if (strlen(outDirPath) > PATH_MAX || strncpy_s(path, PATH_MAX, outDirPath, strlen(outDirPath)) != EOK) { + PRINT_ERR("get path(%s) failed\n", outDirPath); + return -1; + } +#else + if (strlen(outDirPath) > PATH_MAX || realpath(outDirPath, path) == NULL) { + PRINT_ERR("get file(%s) real path failed\n", outDirPath); return -1; } +#endif - if (fileFullPath[pathLen - 1] != '/' && fileFullPath[pathLen - 1] != '\\') { - fileFullPath[pathLen] = '/'; + if (path[pathLen - 1] != '/' && path[pathLen - 1] != '\\') { + path[pathLen] = '/'; } - ret = strncat_s(fileFullPath, PATH_MAX, filename, strlen(filename) + 1); + if (strlen(path) + strlen(filename) + 1 > PATH_MAX) { + PRINT_ERR("length of path too long.\n"); + return -1; + } + ret = strncat_s(path, PATH_MAX, filename, strlen(filename) + 1); if (ret != 0) { PRINT_ERR("strncat_s failed, (%s, %d, %s, %d), errno = %d\n", - fileFullPath, PATH_MAX, filename, (int32_t)strlen(filename) + 1, errno); + path, PATH_MAX, filename, (int32_t)strlen(filename) + 1, errno); return -1; } - fp = fopen(fileFullPath, "wb"); + fp = fopen(path, "wb"); if (fp == NULL) { - PRINT_ERR("can't create file(%s), errno = %d\n", fileFullPath, errno); + PRINT_ERR("can't create file(%s), errno = %d\n", path, errno); return -1; } - ret = fwrite(convertedBuffer, contextBufLen, 1, fp); - if (ret != 1) { - PRINT_ERR("can't write file(%s),errno = %d\n", fileFullPath, errno); + if (fwrite(convertedBuffer, contextBufLen, 1, fp) != 1) { + PRINT_ERR("can't write file(%s),errno = %d\n", path, errno); (void)fclose(fp); return -1; } @@ -144,9 +167,8 @@ static cJSON *CreateWholeSyscapJsonObj(void) int32_t CreatePCID(char *inputFile, char *outDirPath) { - uint8_t sectorOfBits, posOfBits; - int32_t ret, i; - uint32_t contextBufLen, osCapSize, privateCapSize; + int32_t ret, sectorOfBits, posOfBits; + uint32_t i, contextBufLen, privateCapSize, osCapSize; errno_t nRet = 0; char *contextBuffer = NULL; char *systemType = NULL; @@ -268,7 +290,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "system_type"); if (jsonSyscapObj == NULL || !cJSON_IsString(jsonSyscapObj)) { - PRINT_ERR("get \"system_type\" failed, jsonSyscapObj = %p\n", jsonSyscapObj); + PRINT_ERR("get \"system_type\" failed\n"); ret = -1; goto FREE_PCID_BUFFER_OUT; } @@ -308,12 +330,12 @@ FREE_CONVERT_OUT: int32_t DecodePCID(char *inputFile, char *outDirPath) { - int32_t ret, i, j; + int32_t ret; errno_t nRet = 0; char *contextBuffer = NULL; uint8_t osSyscap[BYTES_OF_OS_SYSCAP] = {0}; - uint16_t indexOfSyscap[960] = {0}; - uint32_t contextBufLen, countOfSyscap = 0; + uint16_t indexOfSyscap[BYTES_OF_OS_SYSCAP * BITS_OF_ONE_BYTE] = {0}; + uint32_t i, j, contextBufLen, countOfSyscap = 0; ret = GetFileContext(inputFile, &contextBuffer, &contextBufLen); if (ret != 0) { diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 4874ada099d3505d281a8816ecb91c1bc192a341..88463681279edbbd80e0ac1a93d2e591a5f15225 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -54,20 +54,33 @@ static void FreeContextBuffer(char *contextBuffer) (void)free(contextBuffer); } -static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *bufferLen) +static int32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *bufferLen) { - uint32_t ret; + int32_t ret; FILE *fp = NULL; struct stat statBuf; char *contextBuffer = NULL; + char path[PATH_MAX + 1] = {0x00}; + +#ifdef _POSIX_ + if (strlen(inputFile) > PATH_MAX || strncpy_s(path, PATH_MAX, inputFile, strlen(inputFile)) != EOK) { + PRINT_ERR("get path(%s) failed\n", inputFile); + return -1; + } +#else + if (strlen(inputFile) > PATH_MAX || realpath(inputFile, path) == NULL) { + PRINT_ERR("get file(%s) real path failed\n", inputFile); + return -1; + } +#endif - ret = stat(inputFile, &statBuf); + ret = stat(path, &statBuf); if (ret != 0) { - PRINT_ERR("get file(%s) st_mode failed, errno = %d\n", inputFile, errno); + PRINT_ERR("get file(%s) st_mode failed, errno = %d\n", path, errno); return -1; } if (!(statBuf.st_mode & S_IRUSR)) { - PRINT_ERR("don't have permission to read the file(%s)\n", inputFile); + PRINT_ERR("don't have permission to read the file(%s)\n", path); return -1; } contextBuffer = (char *)malloc(statBuf.st_size + 1); @@ -75,15 +88,15 @@ static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t * PRINT_ERR("malloc buffer failed, size = %d, errno = %d\n", (int32_t)statBuf.st_size + 1, errno); return -1; } - fp = fopen(inputFile, "rb"); + fp = fopen(path, "rb"); if (fp == NULL) { - PRINT_ERR("open file(%s) failed, errno = %d\n", inputFile, errno); + PRINT_ERR("open file(%s) failed, errno = %d\n", path, errno); FreeContextBuffer(contextBuffer); return -1; } ret = fread(contextBuffer, statBuf.st_size, 1, fp); if (ret != 1) { - PRINT_ERR("read file(%s) failed, errno = %d\n", inputFile, errno); + PRINT_ERR("read file(%s) failed, errno = %d\n", path, errno); FreeContextBuffer(contextBuffer); (void)fclose(fp); return -1; @@ -100,35 +113,45 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, char *filename, char { int32_t ret; FILE *fp = NULL; - char fileFullPath[PATH_MAX] = {0}; + char path[PATH_MAX + 1] = {0x00}; int32_t pathLen = strlen(outDirPath); - ret = strncpy_s(fileFullPath, PATH_MAX, outDirPath, pathLen + 1); - if (ret != 0) { - PRINT_ERR("strncpy_s failed, source string:%s, len = %d, errno = %d\n", outDirPath, pathLen + 1, errno); +#ifdef _POSIX_ + if (strlen(outDirPath) > PATH_MAX || strncpy_s(path, PATH_MAX, outDirPath, strlen(outDirPath)) != EOK) { + PRINT_ERR("get path(%s) failed\n", outDirPath); + return -1; + } +#else + if (strlen(outDirPath) > PATH_MAX || realpath(outDirPath, path) == NULL) { + PRINT_ERR("get file(%s) real path failed\n", outDirPath); return -1; } +#endif - if (fileFullPath[pathLen - 1] != '/' && fileFullPath[pathLen - 1] != '\\') { - fileFullPath[pathLen] = '/'; + if (path[pathLen - 1] != '/' && path[pathLen - 1] != '\\') { + path[pathLen] = '/'; } - ret = strncat_s(fileFullPath, PATH_MAX, filename, strlen(filename) + 1); + if (strlen(filename) + 1 > PATH_MAX) { + PRINT_ERR("filename(%s) too long.\n", filename); + return -1; + } + ret = strncat_s(path, PATH_MAX, filename, strlen(filename)); if (ret != 0) { PRINT_ERR("strncat_s failed, (%s, %d, %s, %d), errno = %d\n", - fileFullPath, PATH_MAX, filename, (int32_t)strlen(filename) + 1, errno); + path, PATH_MAX, filename, (int32_t)strlen(filename) + 1, errno); return -1; } - fp = fopen(fileFullPath, "wb"); + fp = fopen(path, "wb"); if (fp == NULL) { - PRINT_ERR("can`t create file(%s), errno = %d\n", fileFullPath, errno); + PRINT_ERR("can`t create file(%s), errno = %d\n", path, errno); return -1; } - ret = fwrite(convertedBuffer, bufferLen, 1, fp); - if (ret != 1) { - PRINT_ERR("can`t write file(%s),errno = %d\n", fileFullPath, errno); + size_t retFwrite = fwrite(convertedBuffer, bufferLen, 1, fp); + if (retFwrite != 1) { + PRINT_ERR("can`t write file(%s),errno = %d\n", path, errno); (void)fclose(fp); return -1; } @@ -143,11 +166,10 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath) int32_t ret; char productName[NAME_MAX] = {0}; char *contextBuffer = NULL; - uint32_t bufferLen; + uint32_t bufferLen, osCapSize, privateCapSize; char *convertedBuffer = NULL; uint32_t convertedBufLen = sizeof(PCIDHead); char *systemType = NULL; - int32_t osCapSize, privateCapSize; PCIDHead *headPtr = NULL; char *fillTmpPtr = NULL; cJSON *cjsonObjectRoot = NULL; @@ -206,6 +228,11 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath) } convertedBuffer = (char *)malloc(convertedBufLen); + if (convertedBuffer == NULL) { + PRINT_ERR("malloc failed.\n"); + ret = -1; + goto FREE_CONTEXT_OUT; + } (void)memset_s(convertedBuffer, convertedBufLen, 0, convertedBufLen); @@ -221,7 +248,7 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath) cjsonObjectPtr = cJSON_GetObjectItem(cjsonObjectRoot, "system_type"); if (cjsonObjectPtr == NULL || !cJSON_IsString(cjsonObjectPtr)) { - PRINT_ERR("get \"system_type\" failed, cjsonObjectPtr = %p\n", cjsonObjectPtr); + PRINT_ERR("get \"system_type\" failed.\n"); ret = -1; goto FREE_CONVERT_OUT; } @@ -250,7 +277,7 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath) // fill osCap Length *(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(osCapSize * SINGLE_FEAT_LENGTH)); fillTmpPtr += sizeof(uint16_t); - for (int32_t i = 0; i < osCapSize; i++) { + for (uint32_t i = 0; i < osCapSize; i++) { arrayItemPtr = cJSON_GetArrayItem(osCapPtr, i); char *pointPos = strchr(arrayItemPtr->valuestring, '.'); if (pointPos == NULL) { @@ -280,7 +307,7 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath) // fill privateCap Length *(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(privateCapSize * SINGLE_FEAT_LENGTH)); fillTmpPtr += sizeof(uint16_t); - for (int32_t i = 0; i < privateCapSize; i++) { + for (uint32_t i = 0; i < privateCapSize; i++) { arrayItemPtr = cJSON_GetArrayItem(privateCapPtr, i); char *pointPos = strchr(arrayItemPtr->valuestring, '.'); if (pointPos == NULL) { @@ -425,7 +452,7 @@ int32_t PCIDDecode(char *inputFile, char *outDirPath) ret = -1; goto FREE_SYSCAP_OUT; } - for (int32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) { + for (uint32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) { if (*(osCapArrayPtr + (i + 1) * SINGLE_FEAT_LENGTH - 1) != '\0') { PRINT_ERR("prase file failed, format is invalid, input file : %s\n", inputFile); ret = -1; @@ -474,7 +501,7 @@ int32_t PCIDDecode(char *inputFile, char *outDirPath) goto FREE_SYSCAP_OUT; } - for (int32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) { + for (uint32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) { if (*(privateCapArrayPtr + (i + 1) * SINGLE_FEAT_LENGTH - 1) != '\0') { PRINT_ERR("prase file failed, format is invalid, input file : %s\n", inputFile); ret = -1; @@ -569,10 +596,9 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath) { int32_t ret; char *contextBuffer = NULL; - uint32_t bufferLen; + uint32_t bufferLen, sysCapSize; char *convertedBuffer = NULL; uint32_t convertedBufLen = sizeof(RPCIDHead); - int32_t sysCapSize; RPCIDHead *headPtr = NULL; char *fillTmpPtr = NULL; cJSON *cjsonObjectRoot = NULL; @@ -595,7 +621,7 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath) sysCapPtr = cJSON_GetObjectItem(cjsonObjectRoot, "syscap"); if (sysCapPtr == NULL || !cJSON_IsArray(sysCapPtr)) { - PRINT_ERR("get \"syscap\" object failed, sysCapPtr = %p\n", sysCapPtr); + PRINT_ERR("get \"syscap\" object failed.\n"); ret = -1; goto FREE_CONTEXT_OUT; } @@ -610,6 +636,11 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath) convertedBufLen += (2 * sizeof(uint16_t) + sysCapSize * SINGLE_FEAT_LENGTH); convertedBuffer = (char *)malloc(convertedBufLen); + if (convertedBuffer == NULL) { + PRINT_ERR("malloc failed\n"); + ret = -1; + goto FREE_CONTEXT_OUT; + } (void)memset_s(convertedBuffer, convertedBufLen, 0, convertedBufLen); headPtr = (RPCIDHead *)convertedBuffer; @@ -629,7 +660,7 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath) // fill osCap Length *(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(sysCapSize * SINGLE_FEAT_LENGTH)); fillTmpPtr += sizeof(uint16_t); - for (int32_t i = 0; i < sysCapSize; i++) { + for (uint32_t i = 0; i < sysCapSize; i++) { arrayItemPtr = cJSON_GetArrayItem(sysCapPtr, i); char *pointPos = strchr(arrayItemPtr->valuestring, '.'); if (pointPos == NULL) { @@ -668,7 +699,7 @@ FREE_CONTEXT_OUT: int32_t RPCIDDecode(char *inputFile, char *outDirPath) { - uint32_t ret; + int32_t ret; char *contextBuffer = NULL; char *contextBufferTail = NULL; uint32_t bufferLen; @@ -720,7 +751,7 @@ int32_t RPCIDDecode(char *inputFile, char *outDirPath) ret = -1; goto FREE_CONTEXT_OUT; } - for (int32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) { + for (uint32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) { if (*(sysCapArrayPtr + (i + 1) * SINGLE_FEAT_LENGTH - 1) != '\0') { PRINT_ERR("prase file failed, format is invalid, input file : %s\n", inputFile); ret = -1; diff --git a/test/unittest/common/syscap_codec_test.cpp b/test/unittest/common/syscap_codec_test.cpp index c8f39e1c2917d89cba55be80aeb3fbd9b23b0b02..356e27164a50826887ef108bc7032103fdcb6cd2 100644 --- a/test/unittest/common/syscap_codec_test.cpp +++ b/test/unittest/common/syscap_codec_test.cpp @@ -34,7 +34,7 @@ void SyscapCodecTest::TearDown() {} */ HWTEST_F(SyscapCodecTest, EncodeOsSyscap, TestSize.Level1) { - char OsInput[128] = {0}; + char OsInput[MAX_SYSCAP_STR_LEN] = {0}; EXPECT_TRUE(EncodeOsSyscap(OsInput)); } @@ -59,12 +59,12 @@ HWTEST_F(SyscapCodecTest, EncodePrivateSyscap, TestSize.Level1) HWTEST_F(SyscapCodecTest, DecodeOsSyscap, TestSize.Level1) { int osSyscap[32] = {1, 3, 3}; - char (*osOutput)[128] = NULL; + char (*osOutput)[MAX_SYSCAP_STR_LEN] = NULL; int decodeOsCnt; char expectOsOutput001[] = "SystemCapability.Account.AppAccount"; char expectOsOutput002[] = "SystemCapability.Account.OsAccount"; EXPECT_TRUE(DecodeOsSyscap((char *)osSyscap, &osOutput, &decodeOsCnt)); - char (*tmpOsOutput)[128] = osOutput; + char (*tmpOsOutput)[MAX_SYSCAP_STR_LEN] = osOutput; EXPECT_STREQ(*tmpOsOutput, expectOsOutput001); EXPECT_STREQ(*(tmpOsOutput + 1), expectOsOutput002); EXPECT_EQ(decodeOsCnt, 2); @@ -78,7 +78,7 @@ HWTEST_F(SyscapCodecTest, DecodeOsSyscap, TestSize.Level1) */ HWTEST_F(SyscapCodecTest, DecodePrivateSyscap, TestSize.Level1) { - char (*priOutput)[128] = NULL; + char (*priOutput)[MAX_SYSCAP_STR_LEN] = NULL; char priSyscap[] = "Device.syscap1GEDR,Device.syscap2WREGW,Vendor.syscap3RGD,Vendor.syscap4RWEG,Vendor.syscap5REWGWE,"; int decodePriCnt; char expectPriOutput001[] = "SystemCapability.Device.syscap1GEDR"; @@ -87,7 +87,7 @@ HWTEST_F(SyscapCodecTest, DecodePrivateSyscap, TestSize.Level1) char expectPriOutput004[] = "SystemCapability.Vendor.syscap4RWEG"; char expectPriOutput005[] = "SystemCapability.Vendor.syscap5REWGWE"; EXPECT_TRUE(DecodePrivateSyscap(priSyscap, &priOutput, &decodePriCnt)); - char (*tmpPtiOutput)[128] = priOutput; + char (*tmpPtiOutput)[MAX_SYSCAP_STR_LEN] = priOutput; EXPECT_STREQ(*tmpPtiOutput++, expectPriOutput001); EXPECT_STREQ(*tmpPtiOutput++, expectPriOutput002); EXPECT_STREQ(*tmpPtiOutput++, expectPriOutput003);