已开启
增加execCmd执行cli tool #20318
增加execCmd执行cli tool #20318
已开启
piki创建于 4 天前
piki
piki
4 天前

IssueNo:

Description:

稳定性自检:

自检项 自检结果
涉及跨进程调用的相关操作需要抛至主线程或加锁防止并发
成员变量进行赋值或创建需要排查并发
谨慎在lambda表达式中使用引用捕获
谨慎在未经拷贝的情况下使用外部传入的string、C字符串
map\vector\list\set等stl模板类使用时需要排查并发
谨慎考虑加锁范围
在IPC通信中谨慎使用同步通信方式
禁止传递this指针至其他模块或线程(特别是eventhandler任务)
禁止将外部传入的裸指针在内部直接构造智能指针
禁止多个独立创建的智能指针管理同一地址
禁止在析构函数中抛异步任务
禁止js对象在非js线程(例如在IPC线程)创建、使用或销毁
禁止在对外接口中未经判空直接使用外部传入的指针
禁止接口返回局部变量引用
禁止在信号函数中加锁
禁止在关键流程(SA启动、应用启动等主流程)执行耗时的操作
禁止将同一个cpp编译在不同的so中

安全编码自检:

自检项 自检结果
裸指针避免通过隐式转换构造为sptr
json对象在取值之前必须先判断类型,避免类型不匹配
序列化时必须对传入的数组大小进行校验,避免出现超大数组
避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型
外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验
指针变量、表示资源描述符的变量、bool变量必须赋初值
readParcelable获取的对象使用前需要判空
分配和释放内存的函数需要成对出现
申请内存后异常退出前需要及时进行内存释放
内存申请前必须对内存大小进行合法性校验
内存分配后必须判断是否成功
禁止使用realloc、alloca函数
禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰
禁止打印内存地址
整数之间运算时必须严格检查,确保不会出现溢出、反转、除0
禁止对有符号整数进行位操作符运算
禁止对指针进行逻辑或位运算
循环次数如果收外部数据控制,需要检验其合法性
禁止使用内存操作类危险函数,需要使用安全函数
谨慎使用不可重入函数
必须检查安全函数的返回值,并进行正确处理
禁止仅通过TokenType类型判断绕过权限校验

TDD Result:

XTS Result:

是否已执行L0用例

AI检视评分(使用本地代码检视skills扫描):

likedislike
合并受阻
pikipiki
4 天前 关联了issue:[新需求]: execCmd执行CLI命令
afwk_helper成员
4 天前 评论:

开始进行AI检视!

AI review has been started, please wait...

likedislike
afwk_helper成员
4 天前 评论:
check type result report
start ai_review pass -
likedislike
openharmony_ciopenharmony_ci成员
4 天前 添加了label:waiting_on_author
openharmony_ci
openharmony_ci成员
4 天前 评论:

感谢提交 Pull Requests!如果您提交的PR已经开发完毕,请评论 "start build" 触发门禁,更多交互操作,请访问OpenHarmony社区支持命令清单。如果需要调整订阅PR、Issue的变更状态,请访问订阅链接


Thanks for submitting the pull request. If your Pull Request has already been developed, you can leave a "start build" comment to trigger the gated system. For more commands, please visit OpenHarmony Command List. If you need to change the subscription of a Pull Request or Issue, please visit the link.

likedislike
此处折叠了46条消息 查看更多
hwliujinwei1 天前进行代码检视1
cli_tool_framework/services/climgr/src/cli_tool_manager_service.cpp
@@ -1107,0 +1130,4 @@
1130+ auto pos = param.cmd.find_first_of(" \t", first);
1131+ std::string toolName = (pos == std::string::npos) ? param.cmd.substr(first) : param.cmd.substr(first, pos - first);
1132+ if (toolName.empty() || toolName[0] == '/') {
1133+ ReportCliExecuteFailed(bundleName, toolName, "invalid_tool_name");
hwliujinwei1 天前评论:

[重要] toolName 校验仅检查 empty 和首字符 '/',未对 '..'、'./'、路径分隔符等特殊字符进行校验。虽然 toolName 主要用于 GetToolByName 查找,但根据安全编码规范'外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验',建议增加对 toolName 的白名单字符校验或拒绝包含路径分隔符的输入。

likedislike
hwliujinwei1 天前进行代码检视1
cli_tool_framework/interfaces/cli_tool/src/cli_tool_mgr_client.cpp
@@ -33,1 +33,4 @@
3333constexpr int32_t ERR_OK = 0;
34+ 
35+std::string ExtractToolName(const std::string &cmd)
36+{
hwliujinwei1 天前评论:

[次要] ExtractToolName 的逻辑与 cli_tool_manager_service.cpp 中 ExecCmdToolMode 内的 toolName 提取逻辑完全重复,建议将其抽取到 ToolUtil 中作为公共静态方法复用,避免逻辑不一致风险。

likedislike
hwliujinwei1 天前进行代码检视1
cli_tool_framework/services/climgr/src/tool_util.cpp
@@ -313,0 +342,4 @@
342+};
343+ 
344+bool TokenizeCommand(const std::string &cmd, std::vector<std::string> &tokens)
345+{
hwliujinwei1 天前评论:

[次要] TokenizeCommand 仅处理单引号,不支持双引号和转义字符。对于包含双引号或嵌套引号的命令字符串可能解析错误。建议在注释或文档中明确说明支持的语法范围,或补充对双引号和反斜杠转义的支持。

likedislike
hwliujinwei1 天前进行代码检视1
cli_tool_framework/interfaces/cli_tool/src/cli_tool_mgr_client.cpp
@@ -86,3 +96,3 @@
8696 }
8797 
88- std::string eventId = CliEventReplyManager::GetInstance().AddEventReplyCallback("shell",
98+ std::string eventKey = param.isShellCommand ? "shell" : ExtractToolName(param.cmd);
hwliujinwei1 天前评论:

[次要] 当 param.isShellCommand 为 false 且 param.cmd 为空或纯空白时,ExtractToolName 返回空字符串作为 eventKey,可能导致注册无法匹配的回调。建议在客户端侧也增加 cmd 非空校验,提前返回错误,避免无效回调注册。

likedislike
hwliujinwei1 天前进行代码检视1
cli_tool_framework/interfaces/cli_tool/src/exec_cmd_param.cpp
@@ -80,0 +81,4 @@
81+ 
82+ // Tail field for backward compat: ReadBool fails on old clients, defaults to true.
83+ result->isShellCommand = true;
84+ if (parcel.ReadBool(result->isShellCommand)) {
hwliujinwei1 天前评论:

[提示] Unmarshalling 中 ReadBool 成功后直接 return result,若未来在 isShellCommand 之后新增字段,此早返回会导致后续字段无法读取。建议移除 if 内的 return,统一在函数末尾返回,保持与 Marshalling 字段顺序的一致性。

likedislike