diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 1e42cbd..ea79d15 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -343,6 +343,10 @@ typedef enum SystemCapabilityNum { RESOURCESCHEDULE_SYSTEMLOAD, MSDP_MULTIMODAL_AWARENESS, ABILITY_APP_STARTUP, + MULTIMEDIA_AVSESSION_EXTENDEDDISPLAYCAST, + MULTIMODALINPUT_INPUT_INFRAREDEMITTER, + MULTIMEDIA_MEDIA_AVTRANSCODER, + MULTIMEDIA_IMAGEEFFECT_CORE, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; @@ -596,6 +600,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Multimedia.AVSession.Core", MULTIMEDIA_AVSESSION_CORE}, {"SystemCapability.Multimedia.AVSession.Manager", MULTIMEDIA_AVSESSION_MANAGER}, {"SystemCapability.Multimedia.AVSession.AVCast", MULTIMEDIA_AVSESSION_AVCAST}, + {"SystemCapability.Multimedia.AVSession.ExtendedDisplayCast", MULTIMEDIA_AVSESSION_EXTENDEDDISPLAYCAST}, {"SystemCapability.Multimedia.Audio.Tone", MULTIMEDIA_AUDIO_TONE}, {"SystemCapability.Multimedia.Audio.Interrupt", MULTIMEDIA_AUDIO_INTERRUPT}, {"SystemCapability.Cloud.AAID", CLOUD_AAID}, @@ -668,7 +673,10 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Resourceschedule.Ffrt.Core", RESOURCESCHEDULE_FFRT_CORE}, {"SystemCapability.AI.MindSporeLite", AI_MINDSPORELITE}, {"SystemCapability.Ability.AppStartup", ABILITY_APP_STARTUP}, + {"SystemCapability.Multimedia.Media.AVTransCoder", MULTIMEDIA_MEDIA_AVTRANSCODER}, {"SystemCapability.Base", BASE}, + {"SystemCapability.MultimodalInput.Input.InfraredEmitter", MULTIMODALINPUT_INPUT_INFRAREDEMITTER}, + {"SystemCapability.Multimedia.ImageEffect.Core", MULTIMEDIA_IMAGEEFFECT_CORE}, }; #ifdef __cplusplus diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index b407613..b26466e 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -89,7 +89,7 @@ bool EncodeOsSyscap(char *output, int len) return false; } - ret = GetFileContext(g_pcidPath, &contextBuffer, &bufferLen); + ret = GetFileContext(PCID_PATH, &contextBuffer, &bufferLen); if (ret != 0) { PRINT_ERR("GetFileContext failed, input file : /system/etc/pcid.sc\n"); return false; @@ -113,12 +113,16 @@ bool EncodePrivateSyscap(char **output, int *outputLen) char *outputStr = NULL; uint32_t bufferLen; - ret = GetFileContext(g_pcidPath, &contextBuffer, &bufferLen); + ret = GetFileContext(PCID_PATH, &contextBuffer, &bufferLen); if (ret != 0) { PRINT_ERR("GetFileContext failed, input file : /system/etc/pcid.sc\n"); return false; } + if (bufferLen < (PCID_MAIN_BYTES + 1) || bufferLen > INT32_MAX) { + PRINT_ERR("Parameter bufferLen out of range."); + return false; + } uint32_t priLen = bufferLen - PCID_MAIN_BYTES - 1; if ((int)priLen <= 0) { *outputLen = 0; @@ -177,18 +181,19 @@ bool DecodeOsSyscap(const char input[PCID_MAIN_BYTES], char (**output)[SINGLE_SY for (i = 0; i < countOfSyscap; i++) { for (j = 0; j < sizeof(g_arraySyscap) / sizeof(SyscapWithNum); j++) { - if (g_arraySyscap[j].num == indexOfSyscap[i]) { - nRet = strcpy_s(*strSyscap, SINGLE_SYSCAP_LEN, g_arraySyscap[j].str); - if (nRet != EOK) { - printf("strcpy_s failed. error = %d\n", nRet); - *outputCnt = 0; - free(strSyscap); - strSyscap = NULL; - return false; - } - strSyscap++; - break; + if (g_arraySyscap[j].num != indexOfSyscap[i]) { + continue; } + nRet = strcpy_s(*strSyscap, SINGLE_SYSCAP_LEN, g_arraySyscap[j].str); + if (nRet != EOK) { + printf("strcpy_s failed. error = %d\n", nRet); + *outputCnt = 0; + free(strSyscap); + strSyscap = NULL; + return false; + } + strSyscap++; + break; } } @@ -241,6 +246,7 @@ bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *o *bufferPos = '\0'; if (sprintf_s(*outputArray, SINGLE_SYSCAP_LEN, "SystemCapability.%s", buffer) == -1) { free(outputArray); + free(output); return false; } bufferPos = buffer; @@ -316,8 +322,6 @@ static int32_t ParseRpcidToJson(char *input, uint32_t inputLen, cJSON *rpcidJson ret = -1; goto FREE_SYSCAP_OUT; } - - return 0; FREE_SYSCAP_OUT: cJSON_Delete(sysCapJson); return ret; @@ -326,24 +330,25 @@ FREE_SYSCAP_OUT: static int32_t TransStringFormatAndSaveSyscap(struct FreeAfterDecodeRpcidInfo freeAfterDecodeRpcidInfo, cJSON *sysCapArray, const char *inputFile) { + int32_t ret = -1; // trans to string format sysCapArray = cJSON_GetObjectItem(freeAfterDecodeRpcidInfo.rpcidRoot, "syscap"); if (sysCapArray == NULL || !cJSON_IsArray(sysCapArray)) { PRINT_ERR("Get syscap failed. Input file: %s\n", inputFile); - return -1; + return ret; } freeAfterDecodeRpcidInfo.sysCapArraySize = cJSON_GetArraySize(sysCapArray); if (freeAfterDecodeRpcidInfo.sysCapArraySize < 0) { PRINT_ERR("Get syscap size failed. Input file: %s\n", inputFile); - return -1; + return ret; } // malloc for save os syscap index freeAfterDecodeRpcidInfo.osSysCapIndex = (uint16_t *)malloc(sizeof(uint16_t) * freeAfterDecodeRpcidInfo.sysCapArraySize); if (freeAfterDecodeRpcidInfo.osSysCapIndex == NULL) { PRINT_ERR("malloc failed.\n"); - return -1; } + free(freeAfterDecodeRpcidInfo.osSysCapIndex); return 0; } diff --git a/src/create_pcid.c b/src/create_pcid.c index 8f37087..0960a0b 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -254,6 +254,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) cJSON *jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "syscap"); if (jsonSyscapObj == NULL || !cJSON_IsObject(jsonSyscapObj)) { PRINT_ERR("get \"syscap\" object failed\n"); + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, -1); } @@ -261,12 +262,14 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) cJSON *jsonPriSyscapObj = cJSON_GetObjectItem(jsonSyscapObj, "private"); ret = GetOsAndPriSyscapSize(jsonOsSyscapObj, jsonPriSyscapObj, &osCapSize, &privateCapSize); if (ret != 0) { + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, ret); } uint16_t allPriSyscapStrLen = 0; ret = GetPriSyscapLen(privateCapSize, jsonPriSyscapObj, &allPriSyscapStrLen); if (ret != 0) { + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, ret); } @@ -274,6 +277,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) PCIDMain *pcidBuffer = (PCIDMain *)malloc(pcidLength); if (pcidBuffer == NULL) { PRINT_ERR("malloc for pcid buffer failed\n"); + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(NULL, allOsSyscapObj, contextBuffer, 0, -1); } (void)memset_s(pcidBuffer, pcidLength, 0, pcidLength); @@ -282,10 +286,12 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) ret += SetPriSyscap(pcidBuffer, jsonPriSyscapObj, privateCapSize, allPriSyscapStrLen); ret += SetPCIDHeader(pcidBuffer, jsonRootObj); if (ret != 0) { + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(pcidBuffer, allOsSyscapObj, contextBuffer, FREE_CREATE_PCID_BUFFER_OUT, ret); } ret = CheckConvertedContextSaveAsFile(outDirPath, pcidBuffer, pcidLength, ret); + cJSON_Delete(jsonRootObj); return FreeAfterCreatePCID(pcidBuffer, allOsSyscapObj, contextBuffer, FREE_CREATE_PCID_BUFFER_OUT, ret); } @@ -305,6 +311,7 @@ int32_t GetOsSyscap(PCIDMain *pcidMain, cJSON *sysCapObject) errno_t nRet = memcpy_s(osSyscap, OS_SYSCAP_BYTES, (uint8_t *)pcidMain + 8, OS_SYSCAP_BYTES); if (nRet != EOK) { PRINT_ERR("memcpy_s failed."); + cJSON_Delete(capVectorPtr); return -1; } @@ -343,11 +350,17 @@ int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufL return -1; } + if (contextBufLen < 0 || contextBufLen > UINT32_MAX) { + PRINT_ERR("the data privateSyscapLen is out of scope."); + return -1; + } + int32_t privateSyscapLen = (int32_t)(contextBufLen - sizeof(PCIDMain) - 1); if (privateSyscapLen < 0) { PRINT_ERR("parse private syscap failed."); return -1; } else if (privateSyscapLen == 0) { + cJSON_Delete(capVectorPtr); return 0; } @@ -361,10 +374,12 @@ int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufL int32_t ret = sprintf_s(fullCapStr, SINGLE_SYSCAP_LEN, "SystemCapability.%s", priSyscapStr); if (ret == -1) { printf("sprintf_s failed\n"); + cJSON_Delete(capVectorPtr); return -1; } if (!cJSON_AddItemToArray(capVectorPtr, cJSON_CreateString(fullCapStr))) { printf("cJSON_AddItemToArray or cJSON_CreateString failed\n"); + cJSON_Delete(capVectorPtr); return -1; } tempPriSyscapStr = priSyscapStr; @@ -375,9 +390,9 @@ int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufL } if (!cJSON_AddItemToObject(sysCapObject, "private", capVectorPtr)) { PRINT_ERR("cJSON_AddItemToObject failed\n"); + cJSON_Delete(capVectorPtr); return -1; } - return 0; } @@ -507,6 +522,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", outDirPath, outputFileName); } + free(strJson); return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_CONVERT_OUT, ret); } @@ -643,9 +659,10 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt if (priSyscapStringLen == 0) { if (!cJSON_AddItemToObject(sysCapObj, "private", sysCapArray)) { PRINT_ERR("Add private syscap array to json failed.\n"); - free(sysCapArray); + cJSON_Delete(sysCapArray); return -1; } + cJSON_Delete(sysCapArray); return 0; } @@ -653,16 +670,17 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt while (token != NULL) { if (!cJSON_AddItemToArray(sysCapArray, cJSON_CreateString(token))) { PRINT_ERR("Add private syscap string to json failed.\n"); - free(sysCapArray); + cJSON_Delete(sysCapArray); return -1; } token = strtok(NULL, ","); } if (!cJSON_AddItemToObject(sysCapObj, "private", sysCapArray)) { PRINT_ERR("Add private syscap array to json failed.\n"); - free(sysCapArray); + cJSON_Delete(sysCapArray); return -1; } + cJSON_Delete(sysCapArray); return 0; } @@ -690,18 +708,22 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) cJSON *rootObj = cJSON_CreateObject(); if (!cJSON_AddItemToObject(rootObj, "syscap", sysCapObj)) { PRINT_ERR("Add syscap to json failed.\n"); + cJSON_Delete(sysCapObj); goto ADD_JSON_FAILED; } if (AddHeaderToJsonObj(pcidHeader, PCID_HEADER, rootObj) != 0) { PRINT_ERR("Add header to json object failed.\n"); + cJSON_Delete(sysCapObj); goto ADD_JSON_FAILED; } if (AddOsSyscapToJsonObj(osSyscap, OS_SYSCAP_NUM, sysCapObj) != 0) { PRINT_ERR("Add os syscap json object failed.\n"); + cJSON_Delete(sysCapObj); goto ADD_JSON_FAILED; } if (AddPriSyscapToJsonObj(priSyscapStr, (uint32_t)strlen(priSyscapStr), sysCapObj) != 0) { PRINT_ERR("Add private syscap json object failed.\n"); + cJSON_Delete(sysCapObj); goto ADD_JSON_FAILED; } // save as json file @@ -714,11 +736,11 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) } ret = 0; - SAVE_FAILED: +SAVE_FAILED: free(jsonBuffer); - ADD_JSON_FAILED: +ADD_JSON_FAILED: cJSON_Delete(rootObj); - PARSE_FAILED: +PARSE_FAILED: free(ctx); return ret; } @@ -752,18 +774,21 @@ static int32_t GetEncodePCIDOut(uint16_t priSyscapCount, uint32_t privateSyscapL output = (char *)malloc(outputLen); if (output == NULL) { PRINT_ERR("malloc failed\n"); + free(output); return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_PRISYSCAP_FULL_OUT, ret); } (void)memset_s(output, outputLen, 0, outputLen); ret = sprintf_s(output, outputLen, "%u", mainSyscap[0]); if (ret == -1) { PRINT_ERR("sprintf_s failed\n"); + free(output); return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); } for (i = 1; i < PCID_OUT_BUFFER; i++) { ret = sprintf_s(output, outputLen, "%s,%u", output, mainSyscap[i]); if (ret == -1) { PRINT_ERR("sprintf_s failed\n"); + free(output); return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); } } @@ -771,6 +796,7 @@ static int32_t GetEncodePCIDOut(uint16_t priSyscapCount, uint32_t privateSyscapL ret = sprintf_s(output, outputLen, "%s,%s", output, freePcidInfo.priSyscapFull + i * SINGLE_SYSCAP_LEN); if (ret == -1) { PRINT_ERR("sprintf_s failed\n"); + free(output); return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); } } @@ -781,6 +807,7 @@ static int32_t GetEncodePCIDOut(uint16_t priSyscapCount, uint32_t privateSyscapL PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", freePcidInfo.outDirPathFinal, outputFileName); } + free(output); return FreeAfterEncodePCID(freePcidInfo, FREE_ENCODE_PCID_OUT, ret); } diff --git a/src/main.c b/src/main.c index a54d331..5e659f2 100644 --- a/src/main.c +++ b/src/main.c @@ -37,6 +37,7 @@ #define INPUT_FILE 8 #define OUTPUT_FILE 9 #define HELP 10 +#define INPUT_FILE_NUM 4 static void PrintHelp(void); static void PrintVersion(void); @@ -85,7 +86,7 @@ int main(int argc, char **argv) break; } if (flag == 'C') { - if (argc != 4 || optind < 0 || optind >= argc) { // 4, argc of ./syscap_tool -C f1 f2 + if (argc != INPUT_FILE_NUM || optind < 0 || optind >= argc) { // 4, argc of ./syscap_tool -C f1 f2 PRINT_ERR("Input file too few or too many.\n"); return -1; } @@ -126,7 +127,12 @@ int32_t OperateByBitMap(char *const *argv, uint16_t bitMap, char *outputpath) case 0x10E: // 0x10E, -Rdsi inputfile printf("-Rdsi is not support currently.\n"); break; case 0x80: // 0x80, -v - (void)OutputVersion(argv[optind], optind); break; + if (optind < 0 || optind >= INPUT_FILE_NUM) { + PRINT_ERR("Input file too few or too many.\n"); + return -1; + } else { + (void)OutputVersion(argv[optind], optind); break; + } default: (void)OutputHelp(); } diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 421e9d1..bd764cd 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -266,6 +266,7 @@ int32_t RPCIDDecode(char *inputFile, char *outputPath) FREE_RPCID_ROOT: cJSON_Delete(rpcidRoot); + free(convertedBuffer); FREE_CONTEXT_OUT: FreeContextBuffer(contextBuffer); return ret; diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py index be014c1..47be694 100755 --- a/tools/syscap_collector.py +++ b/tools/syscap_collector.py @@ -33,14 +33,6 @@ def get_args(): return args -def adjust_syscaps_list(sys_list: list, product: str): - # 调整syscaps_list:如果产品属于standard类,则去掉其中以.Lite结尾的syscap - standard_product = ["default", "ipcamera", "pc", "tablet"] - if product in standard_product: - sys_list = [syscap for syscap in sys_list if not syscap.endswith(".Lite")] - return sys_list - - def dict_to_json(output_path: str, syscaps_dict: dict): """ output diff product syscaps json to output path @@ -59,7 +51,6 @@ def dict_to_json(output_path: str, syscaps_dict: dict): syscaps_list = list(set(syscaps_list)) filename = os.path.join(output_path, f'{product_name}.json') with os.fdopen(os.open(filename, flags, modes), 'w') as f: - syscaps_list = adjust_syscaps_list(syscaps_list, product_name) json.dump({'SysCaps': syscaps_list}, f, indent=4) print("end...") @@ -304,15 +295,6 @@ class BundlePartObj(object): self._build_config_file = bundle_config_file self._loading_config() - def _loading_config(self): - if not os.path.exists(self._build_config_file): - raise Exception("file '{}' doesn't exist.".format( - self._build_config_file), "2011") - self.bundle_info = _read_json_file(self._build_config_file) - if not self.bundle_info: - raise Exception("read file '{}' failed.".format( - self._build_config_file), "2011") - def to_ohos_build(self): _component_info = self.bundle_info.get('component') _subsystem_name = _component_info.get('subsystem') @@ -349,6 +331,15 @@ class BundlePartObj(object): _ohos_build_info['parts'] = {_part_name: _part_info} return _ohos_build_info + def _loading_config(self): + if not os.path.exists(self._build_config_file): + raise Exception("file '{}' doesn't exist.".format( + self._build_config_file), "2011") + self.bundle_info = _read_json_file(self._build_config_file) + if not self.bundle_info: + raise Exception("read file '{}' failed.".format( + self._build_config_file), "2011") + class LoadBuildConfig(object): """load build config file and parse configuration info.""" @@ -368,6 +359,26 @@ class LoadBuildConfig(object): self._parts_module_list = {} self._parts_deps = {} + def parse(self): + """parse part info from build config file.""" + if self._is_load: + return + subsystem_config, parts_path_dict = self._merge_build_config() + parts_config = subsystem_config.get('parts') + self._parts_module_list.update(parts_config) + self._parts_path_dict = parts_path_dict + self._is_load = True + + def parts_path_info(self): + """parts to path info.""" + self.parse() + return self._parts_path_dict + + def parts_info_filter(self, save_part): + if save_part is None: + raise Exception + self._parts_info_dict = { + key: value for key, value in self._parts_info_dict.items() if key in save_part} def _merge_build_config(self): _build_files = self._build_info.get('build_files') is_thirdparty_subsystem = False @@ -398,27 +409,6 @@ class LoadBuildConfig(object): subsystem_config['parts'] = parts_info return subsystem_config, parts_path_dict - def parse(self): - """parse part info from build config file.""" - if self._is_load: - return - subsystem_config, parts_path_dict = self._merge_build_config() - parts_config = subsystem_config.get('parts') - self._parts_module_list.update(parts_config) - self._parts_path_dict = parts_path_dict - self._is_load = True - - def parts_path_info(self): - """parts to path info.""" - self.parse() - return self._parts_path_dict - - def parts_info_filter(self, save_part): - if save_part is None: - raise Exception - self._parts_info_dict = { - key: value for key, value in self._parts_info_dict.items() if key in save_part} - def get_parts_info(source_root_dir, subsystem_info, build_xts=False): """ diff --git a/tools/syscap_config_merge.py b/tools/syscap_config_merge.py index c3d676e..9ab45de 100755 --- a/tools/syscap_config_merge.py +++ b/tools/syscap_config_merge.py @@ -18,6 +18,7 @@ 1. 扩展syscap头文件的枚举定义,须在开始位置标记最小值,且必须大于等于500。 ''' import argparse +import os LICENCE = '''/* * Copyright (c) 2023 Huawei Device Co., Ltd. @@ -151,6 +152,6 @@ if __name__ == '__main__': output_file = args.output full = assemble_header_file(base_file, extern_file) - with open(output_file, 'w') as out: + with os.fdopen(os.open(output_file, os.O_WRONLY | os.O_CREAT, mode=0o640), 'w') as out: out.writelines(full)