diff --git a/BUILD.gn b/BUILD.gn index 870dbae9a6a1b2a8eb82418c228feaf7d495eee1..e658c776b36cab652674ebe71eb57bbe747375e0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -29,6 +29,7 @@ sources_platform_common = [ "./src/create_pcid.c", "./src/endian_internal.c", "./src/context_tool.c", + "./src/common_method.c", ] ohos_executable("syscap_tool_bin") { @@ -97,6 +98,7 @@ if (defined(ohos_lite)) { "./src/context_tool.c", "./src/endian_internal.c", "./src/syscap_tool.c", + "./src/common_method.c", ] deps += [ @@ -107,6 +109,7 @@ if (defined(ohos_lite)) { } } else { ohos_shared_library("syscap_interface_shared") { + branch_protector_ret = "pac_ret" deps = [] if (syscap_codec_config_extern_path != "") { deps += [ ":gen_syscap_define_custom" ] @@ -121,6 +124,7 @@ if (defined(ohos_lite)) { "./src/context_tool.c", "./src/endian_internal.c", "./src/syscap_tool.c", + "./src/common_method.c", ] external_deps = [ "bounds_checking_function:libsec_static", diff --git a/README.md b/README.md index 4ca90a9a3153cf4004c83ba3908b9ef4732a539b..aa3032370646debfa448c3fcd0b4bb88d9054fc0 100644 --- a/README.md +++ b/README.md @@ -18,19 +18,40 @@ Main function: ``` /developtools -├── syscap_codec # root directory -│ ├── include -│ │ └── syscap_tool.h # interfaces -│ └── src -│ │ ├── endian_internel.h # internal big/little endian conversion headers(common for win、mac、linux) -│ │ ├── endian_internel.c # big/little endian conversion implement -│ │ ├── main.c # command line implement -│ │ └── syscap_tool.c # codec implement +├── syscap_codec # syscap codec代码目录 +│ ├── include +│   │ ├──code_config # syscap_tool_shared对外接口定义 +│ │ │  └──syscap_define.h +│ │ ├── context_tool.h +│   │   ├── create_pcid.h +│   │   └── syscap_tool.h +│ ├── interfaces/inner_api # 提供部件之间的接口 +│ │ ├── syscap_interface.c +│ │ └── syscap_interface.h +│ ├── napi # napi 接口实现 +│ │ ├── BUILD.gn +│ │ ├── napi_query_syscap.cpp +│ │ └── query_syscap.js +│ ├── src +│   │   ├── common_method.c +│   │   ├── common_method.h +│   │   ├── context_tool.c +│   │   ├── create_pcid.c +│ │ ├── endian_internal.h # 内部实现的大小端转换接口定义(便于win、mac、linux平台通用) +│ │ ├── endian_internal.c # 大小端转换实现 +│ │ ├── main.c # syscap_tool命令行工具代码实现 +│ │ └── syscap_tool.c # syscap_tool编解码接口的实现 │ └── test -│ | └── syscap_tool_test.c # syscap_tool test codec implement +│ │ └── unittest/common # inner 接口测试代码实现 +│ │  ├── BUILD.gn +│ │  ├── include +│ │  │ └── syscap_codec_test.h +│ │   └── syscap_codec_test.cpp    # syscap_tool功能测试代码实现 | |—— tools -| │ │ -| │ └── syscap_check.py # syscap一致性检查脚本 +| │ ├── requirements.txt +│   │   ├── syscap_check.py # syscap一致性检查脚本 +│   │   ├── syscap_collector.py +| │ └── syscap_config_merge.py ``` ### API @@ -51,7 +72,7 @@ Note: Ubuntu host only avaiable for windows/linux building, MacOs binary should 1. Downlaod SDK(recommonded) -Download daily builds(http://ci.openharmony.cn/dailybuilds) which included SDK. +Download daily builds( https://ci.openharmony.cn/workbench/cicd/dailybuild/dailylist ) which included SDK. 2. Supported Host @@ -62,6 +83,7 @@ Windows x86_64/Linux x86_64/Darwin x86_64 SysCap tools usually integrate to IDE, APP store and bundle tools. Follow instructions for debugging manually: ./syscap_tool -h or ./syscap_tool --help: + ``` ./syscap_tool --help diff --git a/README_ZH.md b/README_ZH.md index a12c3560954ca7c3a4b17610e01b9ff6583a12fb..40dda44ee614237f2913674eeac5435b4ea30ed3 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -19,56 +19,71 @@ 6. pcid与rpcid比较:查询pcid是否满足rpcid的要求,并输出不满足的地方。 ## 代码目录 + ``` /developtools ├── syscap_codec # syscap codec代码目录 -│ ├── include # syscap_tool_shared对外接口定义 -│ │ ├── syscap_define.h -│ │ └── syscap_tool.h +│ ├── include +│   │ ├──code_config # syscap_tool_shared对外接口定义 +│ │ │  └──syscap_define.h +│ │ ├── context_tool.h +│   │   ├── create_pcid.h +│   │   └── syscap_tool.h │ ├── interfaces/inner_api # 提供部件之间的接口 │ │ ├── syscap_interface.c │ │ └── syscap_interface.h │ ├── napi # napi 接口实现 │ │ ├── BUILD.gn │ │ ├── napi_query_syscap.cpp -│ │ └── syscap_interface.h +│ │ └── query_syscap.js │ ├── src -│ │ ├── endian_internel.h # 内部实现的大小端转换接口定义(便于win、mac、linux平台通用) -│ │ ├── endian_internel.c # 大小端转换实现 +│   │   ├── common_method.c +│   │   ├── common_method.h +│   │   ├── context_tool.c +│   │   ├── create_pcid.c +│ │ ├── endian_internal.h # 内部实现的大小端转换接口定义(便于win、mac、linux平台通用) +│ │ ├── endian_internal.c # 大小端转换实现 │ │ ├── main.c # syscap_tool命令行工具代码实现 │ │ └── syscap_tool.c # syscap_tool编解码接口的实现 │ └── test -│ │ ├── unittest/common # inner 接口测试代码实现 -│ │ │ ├── BUILD.gn -│ │ │ ├── include -│ │ │ │ └── syscap_codec_test.h -│ │ │ └── syscap_codec_test.cpp -│ │ └── syscap_tool_test.c # syscap_tool功能测试代码实现 +│ │ └── unittest/common # inner 接口测试代码实现 +│ │  ├── BUILD.gn +│ │  ├── include +│ │  │ └── syscap_codec_test.h +│ │   └── syscap_codec_test.cpp    # syscap_tool功能测试代码实现 | |—— tools -| │ │ -| │ └── syscap_check.py # syscap一致性检查脚本 +| │ ├── requirements.txt +│   │   ├── syscap_check.py # syscap一致性检查脚本 +│   │   ├── syscap_collector.py +| │ └── syscap_config_merge.py ``` ## API + PC端工具,不对外提供API。 -## PC端编译说明 +## PC端编译说明 + syscap_tool PC端可执行文件编译步骤: + 1. 编译命令:参考[编译构建](https://gitee.com/openharmony/build/blob/master/README_zh.md)文档,执行其指定的sdk编译命令来编译整个sdk,syscap_tool会被编译打包到里面。 2. 编译:在目标开发机上运行上面调整好的sdk编译命令,正常编译syscap_tool会输出到sdk平台相关目录下。 注意:ubuntu环境下只能编译windows/linux版本工具,mac版需要在macos开发机上编译。 ## PC端获取说明 + 1. 下载sdk获取(建议) - 通过访问本社区门禁[每日构建](http://ci.openharmony.cn/dailys/dailybuilds)网站,下载最新的ohos-sdk压缩包,并从相应平台的toolchains压缩包中提取syscap_tool。 + 通过访问本社区门禁[每日构建](https://ci.openharmony.cn/workbench/cicd/dailybuild/dailylist)网站,下载最新的ohos-sdk压缩包,并从相应平台的toolchains压缩包中提取syscap_tool。 2. 支持运行环境 Windows x86_64/Linux x86_64/Darwin x86_64 -## 命令帮助 +## 命令帮助 + 本工具一般被IDE、应用市场和包管理器集成,手工调试时可参考以下说明。 使用./syscap_tool -h或者./syscap_tool --help查看: + ```shell syscap_tool -R/P -e/d -i filepath [-o outpath] -h, --help : how to use @@ -86,22 +101,24 @@ syscap_tool -R/P -e/d -i filepath [-o outpath] syscap_tool v1.1.1 ``` + ### 使用示例 + ```shell # 将 rpcid.json 编码为SC格式,文件名rpcid.sc syscap_tool -Rei rpcid.json -o path/ -# 将 pcid.sc 编码为JSON格式,文件名rpcid.json -syscap_tool -Rdi pcid.sc -o path/ +# 将 rpcid.sc 解码为JSON格式,文件名rpcid.json +syscap_tool -Rdi rpcid.sc -o path/ # 将 pcid.json 编码为SC格式,文件名pcid.sc syscap_tool -Pei pcid.json -o path/ -# 将 pcid.sc 编码为JSON格式,文件名pcid.json +# 将 pcid.sc 解码为JSON格式,文件名pcid.json syscap_tool -Pdi pcid.sc -o path/ -# 将 pcid.sc 编码为字符串格式,文件名rpcid.txt -syscap_tool -Resi pcid.sc -o path/ +# 将 rpcid.sc 编码为字符串格式,文件名rpcid.txt +syscap_tool -Resi rpcid.sc -o path/ # 将 pcid.sc 编码为字符串格式,文件名pcid.txt syscap_tool -Pesi pcid.sc -o path/ @@ -115,6 +132,7 @@ syscap_tool -sC "pcidstring" "rpcidstring" # 将字符串格式的 pcid 转为 json 格式,文件名 pcid.json。 syscap_tool -Pdsi pcid.txt -o path/ ``` + **说明:** -o 选项指定输出目录,缺省为当前目录。 ## syscap一致性检查工具 @@ -137,7 +155,7 @@ requirements: prettytable==3.3.0 ``` -使用python3 syscap-check.py -h或python3 syscap-check.py --help查看用法: +使用python3 syscap_check.py -h或python3 syscap_check.py --help查看用法: ```shell usage: syscap_check.py [-h] [-p PROJECT_PATH] -t {component_codec,component_sdk,sdk_codec} @@ -171,12 +189,13 @@ python3 syscap_check.py -p path_of_openarmony -t sdk_codec ``` ## syscap_define.h 文件规则 + - 每一个 SyscapNum 枚举值都唯一对应于一个 syscap 字符串。 - 如果弃用某个 syscap,在对应的枚举值后面注释 "// abandoned" 即可,请勿删除和修改。对应的 syscap 字符串也不需要修改。 - 添加 syscap,请在 SyscapNum 和 g_arraySyscap 末尾添加相应数据。 - 数组 g_arraySyscap 按照 SyscapNum 枚举值从小到大排序。 - ## Release Note + v1.1.0 2022-6-17 添加转字符串格式以及比较功能。 v1.0.0 2022-3-8 首版本,提供Windows/Linux/Mac平台的系统能力编解码。 diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index cbb31669f0a4c021af1a1afe649004dede468ae8..aa8026a12004e25f9cf781a3d654ac752f47cef0 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -354,6 +354,8 @@ typedef enum SystemCapabilityNum { ABILITY_APPEXTENSION_PHOTOEDITOREXTENSION, HIVIEWDFX_HICOLLIE, BUNDLEMANAGER_APPDOMAINVERIFY, + NOTIFICATION_NOTIFICATIONSETTINGS, + MULTIMEDIA_VIDEOPROCESSINGENGINE, SECURITY_CRYPTOFRAMEWORK_KEY, SECURITY_CRYPTOFRAMEWORK_KEY_SYMKEY, SECURITY_CRYPTOFRAMEWORK_KEY_ASYMKEY, @@ -364,7 +366,21 @@ typedef enum SystemCapabilityNum { SECURITY_CRYPTOFRAMEWORK_MAC, SECURITY_CRYPTOFRAMEWORK_KDF, SECURITY_CRYPTOFRAMEWORK_RAND, - MULTIMEDIA_VIDEOPROCESSINGENGINE, + COMMUNICATION_NETMANAGER_WEARABLE_DISTRIBUTED_NET, + GLOBAL_FONTMANAGER, + TELEPHONY_CORESERVICE_ESIM, + DISTRIBUTEDDATAMANAGER_AIP_CORE, + SECURITY_CERTIFICATE_MANAGER_DIALOG, + DRIVER_USBSERIAL_EXTENSION, + DRIVER_SCSI_EXTENSION, + ARKUI_ARKUI_CIRCLE, + RESOURCESCHEDULE_BACKGROUND_PROCESS_MANAGER, + MULTIMODALAWARENESS_MOTION, + DISTRIBUTEDSCHED_APPCOLLABORATION, + MULTIMEDIA_AVSESSION_AVINPUTCAST, + GAME_GAMECONTROLLER, + DISTRIBUTEDDATAMANAGER_DATAINTELLIGENCE_CORE, + MULTIMODALAWARENESS_DEVICESTATUS, // Add before here SYSCAP_BASIC_END = 500, } SyscapNum; @@ -538,6 +554,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.UserIAM.UserAuth.PinAuth", USERIAM_USERAUTH_PINAUTH}, {"SystemCapability.ArkUI.UiAppearance", ARKUI_UIAPPEARANCE}, {"SystemCapability.Security.CertificateManager", SECURITY_CERTIFICATE_MANAGER}, + {"SystemCapability.Security.CertificateManagerDialog", SECURITY_CERTIFICATE_MANAGER_DIALOG}, {"SystemCapability.Graphic.Vulkan", GRAPHIC_VULKAN}, {"SystemCapability.Location.Location.Core", LOCATION_LOCATION_CORE}, {"SystemCapability.Location.Location.Gnss", LOCATION_LOCATION_GNSS}, @@ -620,6 +637,7 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Multimedia.AVSession.Manager", MULTIMEDIA_AVSESSION_MANAGER}, {"SystemCapability.Multimedia.AVSession.AVCast", MULTIMEDIA_AVSESSION_AVCAST}, {"SystemCapability.Multimedia.AVSession.ExtendedDisplayCast", MULTIMEDIA_AVSESSION_EXTENDEDDISPLAYCAST}, + {"SystemCapability.Multimedia.AVSession.AVInputCast", MULTIMEDIA_AVSESSION_AVINPUTCAST}, {"SystemCapability.Multimedia.Audio.Tone", MULTIMEDIA_AUDIO_TONE}, {"SystemCapability.Multimedia.Audio.Interrupt", MULTIMEDIA_AUDIO_INTERRUPT}, {"SystemCapability.Cloud.AAID", CLOUD_AAID}, @@ -692,7 +710,7 @@ 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.Multimedia.Media.AVTranscoder", MULTIMEDIA_MEDIA_AVTRANSCODER}, {"SystemCapability.Base", BASE}, {"SystemCapability.MultimodalInput.Input.InfraredEmitter", MULTIMODALINPUT_INPUT_INFRAREDEMITTER}, {"SystemCapability.Multimedia.ImageEffect.Core", MULTIMEDIA_IMAGEEFFECT_CORE}, @@ -702,6 +720,8 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Customization.CustomConfig", CUSTOMIZATION_CUSTOMCONFIG}, {"SystemCapability.Ability.AppExtension.PhotoEditorExtension", ABILITY_APPEXTENSION_PHOTOEDITOREXTENSION}, {"SystemCapability.BundleManager.AppDomainVerify", BUNDLEMANAGER_APPDOMAINVERIFY}, + {"SystemCapability.Notification.NotificationSettings", NOTIFICATION_NOTIFICATIONSETTINGS}, + {"SystemCapability.Multimedia.VideoProcessingEngine", MULTIMEDIA_VIDEOPROCESSINGENGINE}, {"SystemCapability.Security.CryptoFramework.Key", SECURITY_CRYPTOFRAMEWORK_KEY}, {"SystemCapability.Security.CryptoFramework.Key.SymKey", SECURITY_CRYPTOFRAMEWORK_KEY_SYMKEY}, {"SystemCapability.Security.CryptoFramework.Key.AsymKey", SECURITY_CRYPTOFRAMEWORK_KEY_ASYMKEY}, @@ -712,7 +732,20 @@ const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Security.CryptoFramework.Mac", SECURITY_CRYPTOFRAMEWORK_MAC}, {"SystemCapability.Security.CryptoFramework.Kdf", SECURITY_CRYPTOFRAMEWORK_KDF}, {"SystemCapability.Security.CryptoFramework.Rand", SECURITY_CRYPTOFRAMEWORK_RAND}, - {"SystemCapability.Multimedia.VideoProcessingEngine", MULTIMEDIA_VIDEOPROCESSINGENGINE}, + {"SystemCapability.Communication.NetManager.WearableDistributedNet", + COMMUNICATION_NETMANAGER_WEARABLE_DISTRIBUTED_NET}, + {"SystemCapability.Global.FontManager", GLOBAL_FONTMANAGER}, + {"SystemCapability.Telephony.CoreService.Esim", TELEPHONY_CORESERVICE_ESIM}, + {"SystemCapability.DistributedDataManager.AIP.Core", DISTRIBUTEDDATAMANAGER_AIP_CORE}, + {"SystemCapability.Driver.UsbSerial.Extension", DRIVER_USBSERIAL_EXTENSION}, + {"SystemCapability.Driver.SCSI.Extension", DRIVER_SCSI_EXTENSION}, + {"SystemCapability.ArkUI.ArkUI.Circle", ARKUI_ARKUI_CIRCLE}, + {"SystemCapability.Resourceschedule.BackgroundProcessManager", RESOURCESCHEDULE_BACKGROUND_PROCESS_MANAGER}, + {"SystemCapability.MultimodalAwarness.Motion", MULTIMODALAWARENESS_MOTION}, + {"SystemCapability.DistributedSched.AppCollaboration", DISTRIBUTEDSCHED_APPCOLLABORATION}, + {"SystemCapability.Game.GameController", GAME_GAMECONTROLLER}, + {"SystemCapability.DistributedDataManager.DataIntelligence.Core", DISTRIBUTEDDATAMANAGER_DATAINTELLIGENCE_CORE}, + {"SystemCapability.MultimodalAwareness.DeviceStatus", MULTIMODALAWARENESS_DEVICESTATUS}, }; #ifdef __cplusplus diff --git a/include/context_tool.h b/include/context_tool.h index b8b437a10dd008ae47bf33696c52a6ba54eedc10..2160be70ea3e5d1dda9aec119df9c51e5dcc7eb5 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/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 017eb5b7523edf5f04b7d9d111ae090cc219db0f..7a8442e6a81996a3f73539a71e057588193ed894 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -26,6 +26,7 @@ #include "endian_internal.h" #include "syscap_interface.h" #include "context_tool.h" +#include "common_method.h" #ifdef SYSCAP_DEFINE_EXTERN_ENABLE #include "syscap_define_custom.h" @@ -292,6 +293,10 @@ static int32_t ParseRpcidToJson(char *input, uint32_t inputLen, cJSON *rpcidJson char *sysCapBegin = input + sizeof(RPCIDHead) + sizeof(uint32_t); RPCIDHead *rpcidHeader = (RPCIDHead *)input; cJSON *sysCapJson = cJSON_CreateArray(); + if (sysCapJson == NULL) { + PRINT_ERR("Get sysCapJson failed, sysCapJson is empty.\n"); + ret = -1; + } for (i = 0; i < sysCapCount; i++) { char *temp = sysCapBegin + i * SINGLE_FEAT_LEN; if (strlen(temp) >= SINGLE_FEAT_LEN) { @@ -443,7 +448,7 @@ static char *FreeAfterDecodeRpcidToString(struct FreeAfterDecodeRpcidInfo freeAf { switch (type) { case FREE_MALLOC_PRISYSCAP_AFTER_DECODE_RPCID: - free(freeAfterDecodeRpcidInfo.priSyscap); + SafeFree(freeAfterDecodeRpcidInfo.priSyscap); free(freeAfterDecodeRpcidInfo.osSysCapIndex); cJSON_Delete(freeAfterDecodeRpcidInfo.sysCapDefine); cJSON_Delete(freeAfterDecodeRpcidInfo.rpcidRoot); @@ -495,6 +500,11 @@ char *DecodeRpcidToStringFormat(const char *inputFile) // parse rpcid to json freeAfterDecodeRpcidInfo.rpcidRoot = cJSON_CreateObject(); + if (freeAfterDecodeRpcidInfo.rpcidRoot == NULL) { + PRINT_ERR("Failed to create cJSON object for rpcidRoot\n"); + return FreeAfterDecodeRpcidToString(freeAfterDecodeRpcidInfo, FREE_CONTEXT_OUT_AFTER_DECODE_RPCID, outBuffer); + } + if (ParseRpcidToJson(freeAfterDecodeRpcidInfo.contextBuffer, bufferLen, freeAfterDecodeRpcidInfo.rpcidRoot)) { PRINT_ERR("Prase rpcid to json failed. Input file: %s\n", inputFile); return FreeAfterDecodeRpcidToString(freeAfterDecodeRpcidInfo, FREE_RPCID_ROOT_AFTER_DECODE_RPCID, outBuffer); @@ -615,6 +625,12 @@ static int32_t ComparePcidWithPriSyscap(struct PcidPriSyscapInfo pcidPriSyscapIn free(temp); return -1; } + 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; ++prisyscapFlag; } diff --git a/interfaces/inner_api/syscap_interface.h b/interfaces/inner_api/syscap_interface.h index a26bfae415257e5679e97e31f68875786ab419de..f0c4bd59494af4f914ede45ede26b7271bea294b 100644 --- a/interfaces/inner_api/syscap_interface.h +++ b/interfaces/inner_api/syscap_interface.h @@ -26,7 +26,7 @@ #define PCID_MAIN_BYTES 128 #define PCID_MAIN_INTS 32 -#define E_EORROR (-1) +#define E_ERROR (-1) #define E_OK 0 #define E_APIVERSION 1 #define E_SYSCAP 2 @@ -54,7 +54,7 @@ char *DecodeRpcidToStringFormat(const char *inputFile); * rpcidString, input string format rpcid. * result, output comparison results. * retval: - * E_EORROR, compare failed. + * E_ERROR, compare failed. * E_OK, compare successful and meet the requirements. * E_APIVERSION, compare successful but api version too low. * E_SYSCAP, compare successful but missing some syscaps. diff --git a/src/common_method.c b/src/common_method.c new file mode 100644 index 0000000000000000000000000000000000000000..cf7880f668cf97524f2adc221be591510b2a197d --- /dev/null +++ b/src/common_method.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common_method.h" +#include + +void SafeFree(char *pointer) +{ + if ((pointer) != NULL) { + free(pointer); + } +} diff --git a/src/common_method.h b/src/common_method.h new file mode 100644 index 0000000000000000000000000000000000000000..a9030bbc6af74059c1cc4e928e7537542bb7f3b2 --- /dev/null +++ b/src/common_method.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COMMON_METHOD_H +#define COMMON_METHOD_H + +#include + +void SafeFree(char *pointer); + +#endif \ No newline at end of file diff --git a/src/context_tool.c b/src/context_tool.c index 1440a6bc3c60a28a667742b63f39c41140d630af..bb243efca2946bd65c89b7b6fe5e70eaaf647c86 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; + } + int32_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; @@ -155,23 +168,25 @@ int32_t CheckRpcidFormat(const char *inputFile, char **buffer, uint32_t *len) } if (bufferLen < (2 * sizeof(uint32_t))) { // 2, header of rpcid.sc PRINT_ERR("Parse file failed(format is invalid), input file : %s\n", inputFile); - free(contextBuffer); + FreeContextBuffer(contextBuffer); return -1; } rpcidHeader = (RPCIDHead *)contextBuffer; if (rpcidHeader->apiVersionType != 1) { PRINT_ERR("Parse file failed(apiVersionType != 1), input file : %s\n", inputFile); - free(contextBuffer); + FreeContextBuffer(contextBuffer); return -1; } sysCaptype = NtohsInter(*(uint16_t *)(rpcidHeader + 1)); if (sysCaptype != 2) { // 2, app syscap type PRINT_ERR("Parse file failed(sysCaptype != 2), input file : %s\n", inputFile); + FreeContextBuffer(contextBuffer); return -1; } sysCapLength = NtohsInter(*(uint16_t *)((char *)(rpcidHeader + 1) + sizeof(uint16_t))); if (bufferLen < sizeof(RPCIDHead) + sizeof(uint32_t) + sysCapLength) { PRINT_ERR("Parse file failed(SysCap length exceeded), input file : %s\n", inputFile); + FreeContextBuffer(contextBuffer); return -1; } diff --git a/src/create_pcid.c b/src/create_pcid.c index 4972ac92879591ab66fb310e38c6c5751389d63f..1b08215bc22b6d05260ac2ba526223c29de62bab 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -25,6 +25,7 @@ #include "endian_internal.h" #include "create_pcid.h" #include "context_tool.h" +#include "common_method.h" #ifdef SYSCAP_DEFINE_EXTERN_ENABLE #include "syscap_define_custom.h" @@ -58,7 +59,6 @@ struct FreeEncodePcidInfo { char *outDirPathFinal; }; - struct FreeDecodePcidJsonInfo { char *strJson; char *contextBuffer; @@ -249,11 +249,10 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) uint32_t privateCapSize, osCapSize; uint32_t contextBufLen; char *contextBuffer = NULL; - cJSON *allOsSyscapObj = CreateWholeSyscapJsonObj(); - int32_t ret = GetFileContext(inputFile, &contextBuffer, (uint32_t *)&contextBufLen); + cJSON *allOsSyscapObj = CreateWholeSyscapJsonObj(); + 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); } @@ -271,6 +270,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath) cJSON *jsonOsSyscapObj = cJSON_GetObjectItem(jsonSyscapObj, "os"); cJSON *jsonPriSyscapObj = cJSON_GetObjectItem(jsonSyscapObj, "private"); + ret = GetOsAndPriSyscapSize(jsonOsSyscapObj, jsonPriSyscapObj, &osCapSize, &privateCapSize); if (ret != 0) { return PreFreeAfterCreatePCID(NULL, allOsSyscapObj, jsonRootObj, contextBuffer, 0); @@ -358,7 +358,7 @@ static int32_t GetPriSyscapResult(cJSON *capVectorPtr, int32_t ret) return ret; } -int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufLen) +static int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, int32_t contextBufLen) { cJSON *capVectorPtr = cJSON_CreateArray(); if (capVectorPtr == NULL) { @@ -366,12 +366,7 @@ int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufL return -1; } - if (contextBufLen > UINT32_MAX) { - PRINT_ERR("the data privateSyscapLen is out of scope."); - return GetPriSyscapResult(capVectorPtr, -1); - } - - int32_t privateSyscapLen = (int32_t)(contextBufLen - sizeof(PCIDMain) - 1); + int32_t privateSyscapLen = contextBufLen - sizeof(PCIDMain) - 1; if (privateSyscapLen < 0 || privateSyscapLen > INT32_MAX) { PRINT_ERR("parse private syscap failed."); return GetPriSyscapResult(capVectorPtr, -1); @@ -384,6 +379,11 @@ int32_t GetPriSyscap(PCIDMain *pcidMain, cJSON *sysCapObject, size_t contextBufL char *tempPriSyscapStr = priSyscapStr; char *ptrPrivateSyscap = (char *)(pcidMain + 1); while (*ptrPrivateSyscap != '\0') { + size_t currentLen = tempPriSyscapStr - priSyscapStr; + if (currentLen >= SINGLE_SYSCAP_LEN - 1) { + printf("Syscap name exceeds maximum length\n"); + return GetPriSyscapResult(capVectorPtr, -1); + } if (*ptrPrivateSyscap == ',') { *tempPriSyscapStr = '\0'; int32_t ret = sprintf_s(fullCapStr, SINGLE_SYSCAP_LEN, "SystemCapability.%s", priSyscapStr); @@ -452,9 +452,8 @@ static int32_t FreeAfterDecodePCID(struct FreeDecodePcidJsonInfo freePcidJsonInf { switch (type) { case FREE_DECODE_PCID_CONVERT_OUT: - free(freePcidJsonInfo.strJson); + cJSON_free(freePcidJsonInfo.strJson); cJSON_Delete(freePcidJsonInfo.jsonRootObj); - cJSON_Delete(freePcidJsonInfo.sysCapObj); FreeContextBuffer(freePcidJsonInfo.contextBuffer); break; case FREE_DECODE_PCID_ROOT_OUT: @@ -467,6 +466,9 @@ static int32_t FreeAfterDecodePCID(struct FreeDecodePcidJsonInfo freePcidJsonInf FreeContextBuffer(freePcidJsonInfo.contextBuffer); break; case FREE_DECODE_PCID_CONTEXT_OUT: + cJSON_Delete(freePcidJsonInfo.sysCapObj); + FreeContextBuffer(freePcidJsonInfo.contextBuffer); + break; default: FreeContextBuffer(freePcidJsonInfo.contextBuffer); } @@ -484,9 +486,8 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) freePcidJsonInfo.sysCapObj = NULL; freePcidJsonInfo.flag = 0; - 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; } @@ -499,8 +500,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) } /* system type */ - char *systemType = pcidMain->systemType == 0b001 ? "mini" : - (pcidMain->systemType == 0b010 ? "small" : + char *systemType = pcidMain->systemType == 0b001 ? "mini" :(pcidMain->systemType == 0b010 ? "small" : (pcidMain->systemType == 0b100 ? "standard" : NULL)); if (systemType == NULL) { PRINT_ERR("prase file failed, systemType is invaild, %u\n", pcidMain->systemType); @@ -526,15 +526,17 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_ROOT_OUT, ret); } - freePcidJsonInfo.sysCapObj = NULL; // avoid being released repeatedly. + freePcidJsonInfo.strJson = cJSON_Print(freePcidJsonInfo.jsonRootObj); + if (freePcidJsonInfo.strJson == NULL) { + return FreeAfterDecodePCID(freePcidJsonInfo, FREE_DECODE_PCID_ROOT_OUT, -1); + } - char *strJson = cJSON_Print(freePcidJsonInfo.jsonRootObj); const char outputFileName[] = "pcid.json"; - ret = ConvertedContextSaveAsFile(outDirPath, outputFileName, strJson, strlen(strJson)); + ret = ConvertedContextSaveAsFile(outDirPath, outputFileName, freePcidJsonInfo.strJson, + strlen(freePcidJsonInfo.strJson)); 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); } @@ -620,7 +622,7 @@ static int32_t AddOsSyscapToJsonObj(uint32_t *osSyscapArray, uint32_t osSyscapAr if (osSyscapArrayLen != OS_SYSCAP_NUM) { PRINT_ERR("Input os syscap array len error.\n"); - free(sysCapArray); + cJSON_Delete(sysCapArray); return -1; } uint8_t *osSysCapArrayUint8 = (uint8_t *)osSyscapArray; @@ -643,7 +645,7 @@ static int32_t AddOsSyscapToJsonObj(uint32_t *osSyscapArray, uint32_t osSyscapAr } if (!cJSON_AddItemToArray(sysCapArray, cJSON_CreateString(g_arraySyscap[j].str))) { PRINT_ERR("Add os syscap string to json failed.\n"); - free(sysCapArray); + cJSON_Delete(sysCapArray); return -1; } break; @@ -652,7 +654,7 @@ static int32_t AddOsSyscapToJsonObj(uint32_t *osSyscapArray, uint32_t osSyscapAr if (!cJSON_AddItemToObject(sysCapObj, "os", sysCapArray)) { PRINT_ERR("Add os syscap item to json object failed.\n"); - free(sysCapArray); + cJSON_Delete(sysCapArray); return -1; } return 0; @@ -665,7 +667,6 @@ static int32_t AddPriSyscapToJsonObj(char *priSyscapString, uint32_t priSyscapSt cJSON *sysCapArray = cJSON_CreateArray(); if (sysCapArray == NULL) { PRINT_ERR("Create cJSON array failed.\n"); - free(sysCapArray); return -1; } if (priSyscapStringLen == 0) { @@ -697,11 +698,14 @@ 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) { PRINT_ERR("GetFileContext failed, input file : %s\n", input); - free(ctx); return -1; } if (ParseStringSyscap(ctx, osSyscap, OS_SYSCAP_NUM, pcidHeader, PCID_HEADER) != 0) { @@ -719,6 +723,8 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) uint32_t osSyscap[OS_SYSCAP_NUM] = {0}; uint32_t pcidHeader[PCID_HEADER]; char *priSyscapStr = NULL; + char *jsonBuffer = NULL; + ret = GetSyscapStr(input, priSyscapStr, osSyscap, pcidHeader); if (ret == -1) { return ret; @@ -727,40 +733,44 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath) // add to json object cJSON *sysCapObj = cJSON_CreateObject(); cJSON *rootObj = cJSON_CreateObject(); + if (sysCapObj == NULL || rootObj == NULL) { + PRINT_ERR("Failed to create cJSON objects.\n"); + goto FAILED; + } + if (!cJSON_AddItemToObject(rootObj, "syscap", sysCapObj)) { PRINT_ERR("Add syscap to json failed.\n"); - goto ADD_JSON_FAILED; + goto FAILED; } if (AddHeaderToJsonObj(pcidHeader, PCID_HEADER, rootObj) != 0) { PRINT_ERR("Add header to json object failed.\n"); - goto ADD_JSON_FAILED; + goto FAILED; } if (AddOsSyscapToJsonObj(osSyscap, OS_SYSCAP_NUM, sysCapObj) != 0) { PRINT_ERR("Add os syscap json object failed.\n"); - goto ADD_JSON_FAILED; + goto FAILED; } - if (AddPriSyscapToJsonObj(priSyscapStr, (uint32_t)strlen(priSyscapStr), sysCapObj) != 0) { + if (AddPriSyscapToJsonObj(priSyscapStr, (uint32_t) strlen(priSyscapStr), sysCapObj) != 0) { PRINT_ERR("Add private syscap json object failed.\n"); - goto ADD_JSON_FAILED; + goto FAILED; } // save as json file - char *jsonBuffer = cJSON_Print(rootObj); + jsonBuffer = cJSON_Print(rootObj); if (jsonBuffer == NULL) { PRINT_ERR("json buffer is null.\n"); - goto ADD_JSON_FAILED; + goto FAILED; } const char outputFileName[] = "pcid.json"; - if (ConvertedContextSaveAsFile(outDirPath, outputFileName, - jsonBuffer, strlen(jsonBuffer)) != 0) { + if (ConvertedContextSaveAsFile(outDirPath, outputFileName, jsonBuffer, strlen(jsonBuffer)) != 0) { PRINT_ERR("Save as json file failed.\n"); - goto SAVE_FAILED; + goto FAILED; } ret = 0; -SAVE_FAILED: - free(jsonBuffer); -ADD_JSON_FAILED: +FAILED: + cJSON_free(jsonBuffer); + SafeFree(priSyscapStr); cJSON_Delete(sysCapObj); cJSON_Delete(rootObj); return ret; @@ -872,9 +882,8 @@ int32_t EncodePcidscToString(char *inputFile, char *outDirPath) freePcidInfo.outDirPathFinal = outDirPath; PCIDMain *pcidMain = NULL; - 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/main.c b/src/main.c index 2fd051acf58588d0dcae63968ab877a31e0219e4..4593ddf26fbe04849f8c95815ae39d1a6d4de81a 100644 --- a/src/main.c +++ b/src/main.c @@ -212,7 +212,6 @@ void PrintHelp(void) void OutputVersion(const char *arg, int opt) { if (arg != NULL && opt > 1) { - printf("syscap_tool: extra operand \"%s\"\n", arg); printf("Try 'syscap_tool --help' for more information.\n"); } else { (void)PrintVersion(); diff --git a/src/syscap_tool.c b/src/syscap_tool.c index b2ab4fdb4581cd1dbd7cd0b19f4e2d5e44e130a7..d58259b464d07d5c7b08fe06db8d4528ffdb46b2 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -27,6 +27,7 @@ #include "create_pcid.h" #include "syscap_tool.h" #include "context_tool.h" +#include "common_method.h" #ifdef SYSCAP_DEFINE_EXTERN_ENABLE #include "syscap_define_custom.h" @@ -71,6 +72,14 @@ struct FreeAfterEncodeRpcidscInfo { int16_t flag; }; +static void FreePointerMemory(char *pcidContent, char *rpcidContent, char *pcidPriSyscap, char *rpcidPriSyscap) +{ + SafeFree(pcidContent); + SafeFree(rpcidPriSyscap); + SafeFree(rpcidContent); + SafeFree(pcidPriSyscap); +} + static int32_t FillOsCapLength(char *convertedBuffer, char *contextBuffer, struct JsonObjectSysCap gJsonObjectSysCap, uint32_t sysCapSize, int32_t ret) { @@ -141,8 +150,7 @@ int32_t RPCIDEncode(char *inputFile, char *outputPath) gJsonObjectSysCap.cjsonObjectRoot = NULL; gJsonObjectSysCap.sysCapPtr = NULL; - if (GetFileContext(inputFile, &contextBuffer, &bufferLen) != 0) { - PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); + if (CheckFileAndGetFileContext(inputFile, &contextBuffer, &bufferLen) != 0) { return -1; } @@ -204,6 +212,11 @@ static int32_t ParseRpcidToJson(char *input, uint32_t inputLen, cJSON *rpcidJson char *sysCapBegin = input + sizeof(RPCIDHead) + sizeof(uint32_t); RPCIDHead *rpcidHeader = (RPCIDHead *)input; cJSON *sysCapJson = cJSON_CreateArray(); + if (sysCapJson == NULL) { + PRINT_ERR("Failed to create sysCapJson array\n"); + return -1; + } + for (i = 0; i < sysCapCount; i++) { char *temp = sysCapBegin + i * SINGLE_FEAT_LEN; if (strlen(temp) >= SINGLE_FEAT_LEN || strlen(temp) == 0) { @@ -248,6 +261,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); @@ -263,14 +281,18 @@ int32_t RPCIDDecode(char *inputFile, char *outputPath) // save to json file convertedBuffer = cJSON_Print(rpcidRoot); + if (convertedBuffer == NULL) { + PRINT_ERR("cJSON_Print failed to create JSON string\n"); + goto FREE_RPCID_ROOT; + } + ret = ConvertedContextSaveAsFile(outputPath, "rpcid.json", convertedBuffer, strlen(convertedBuffer)); if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outputPath:%s, filename:rpcid.json\n", outputPath); - free(convertedBuffer); + cJSON_free(convertedBuffer); goto FREE_RPCID_ROOT; } - free(convertedBuffer); - + cJSON_free(convertedBuffer); FREE_RPCID_ROOT: cJSON_Delete(rpcidRoot); FREE_CONTEXT_OUT: @@ -462,6 +484,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); @@ -681,6 +708,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); @@ -705,10 +737,7 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t typ &rpcidPriSyscap, &rpcidPriSyscapLen); if (ret != 0) { PRINT_ERR("Separate syscap from string failed. ret = %d\n", ret); - free(pcidContent); - free(rpcidContent); - free(pcidPriSyscap); - free(rpcidPriSyscap); + FreePointerMemory(pcidContent, rpcidContent, pcidPriSyscap, rpcidPriSyscap); return -1; } @@ -720,5 +749,6 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile, uint32_t typ } else { printf("Fail! The pcid does not meet the rpcid\n"); } + return 0; -} \ No newline at end of file +} diff --git a/test/unittest/common/BUILD.gn b/test/unittest/common/BUILD.gn index 668ac7ded2f1467ea3f9c6cee20268b6d330922e..262134296f2008458458a825b58e9adc52aff787 100644 --- a/test/unittest/common/BUILD.gn +++ b/test/unittest/common/BUILD.gn @@ -41,6 +41,7 @@ if (defined(ohos_lite)) { "../../../src/create_pcid.c", "../../../src/endian_internal.c", "../../../src/syscap_tool.c", + "../../../src/common_method.c", "syscap_codec_test.cpp", ] @@ -82,6 +83,7 @@ if (defined(ohos_lite)) { "../../../src/create_pcid.c", "../../../src/endian_internal.c", "../../../src/syscap_tool.c", + "../../../src/common_method.c", "syscap_codec_test.cpp", ] diff --git a/tools/syscap_check.py b/tools/syscap_check.py index e2b97facd49aca5b8879bede98a360f8012657bb..c404369390a615b29bf45dd734f323b0cc96e880 100644 --- a/tools/syscap_check.py +++ b/tools/syscap_check.py @@ -114,8 +114,7 @@ def collect_syscap_from_codec(filepath: str, pattern: str = r'{"(.*)"') -> tuple def collect_syscap_from_component(project_path: str, black_dirs: tuple, key_heirarchy: tuple, - bundles: list = None, - ) -> tuple: + bundles: list = None) -> tuple: """ 从部件的bundle.json中收集syscap :param project_path: 项目根路径 @@ -136,6 +135,7 @@ def collect_syscap_from_component(project_path: str, for line in output: line = line.strip() read_value_from_json(line, key_heirarchy, result_dict, post_handler=bundle_syscap_post_handler) + output.close() else: for bundle in bundles: read_value_from_json(bundle, key_heirarchy, result_dict, post_handler=bundle_syscap_post_handler) diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py index 18ee661ba2099ae81ba212b89b7dae5f809a7bae..74c0f963146ee14ffe8b0b3eca255fca5e8fc175 100755 --- a/tools/syscap_collector.py +++ b/tools/syscap_collector.py @@ -208,7 +208,7 @@ def _check_path_prefix(paths): def traversal_files(subsystem_path, _files): for item in os.scandir(subsystem_path): - if is_symlik(item.path): + if is_symlink(item.path): continue elif item.is_file() and item.name == 'ohos.build': _files.append(item.path) @@ -230,7 +230,7 @@ def get_file_type(file_path): return 'unknown' -def is_symlik(file_path): +def is_symlink(file_path): file_type = get_file_type(file_path) if file_type == 'symlink': link_target = os.readlink(file_path)