已合并
fix(build): harden shell command invocation #884
liu-wei创建于 5月23日
fix(build): harden shell command invocation #884
已合并
liu-wei创建于 5月23日
liu-wei
liu-wei成员
5月23日

描述

加固 build 脚本中的 shell 命令调用,防止特殊字符导致的注入和误解析问题。

主要改动

  1. 变量加引号 - 防止文件名含空格/特殊字符时产生 word splitting 和 globbing

    • cat $CHANGED_FILEScat "$CHANGED_FILES"
    • rm -rf ${BUILD_PATH}/*rm -rf "${BUILD_PATH}"/*
  2. 移除不必要的 bash -c - 直接执行命令,减少 shell 解析复杂度

    • bash -c "find ${SRC_DIR} ..."find "${SRC_DIR}" ...
    • bash -c "python3 script.py $arg"python3 "script.py" "$arg"
  3. 修复 install.sh 的 bug

    • 修复 $0rn typo → $orn
    • 增加安全检查:判断目录存在后再删除

影响范围

  • build.sh
  • cmake/gen_ops_info.cmake
  • cmake/symbol.cmake
  • cmake/ut.cmake
  • scripts/custom/install.sh
  • tests/ut/op_kernel/scripts/gen_tiling_head_file.sh

安全收益

  • 防止含空格/特殊字符的文件路径导致注入
  • 减少对 shell 解析的依赖,提高可移植性
  • 修复潜在的路径遍历漏洞

关联的Issue

关联 Issue: https://gitcode.com/cann/ops-cv/issues/391

测试

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 liu-wei 的贡献)
liu-weiliu-wei成员
5月23日 创建了 pull request,commit ab2a8cf3
CANN-robot
CANN-robot成员
5月23日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/ops-cv 张磊, 徐鲁威 (2/2) 张磊 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

liu-wei, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robot成员
5月23日 添加了label:cann-cla/yes
CANN-robotCANN-robot成员
5月23日 将zhou-qilong,rxtfeng,loov1,zl_hw,llimwang,gubaocheng设为评审人
CANN-robotCANN-robot成员
5月23日 将zhou-qilong,rxtfeng,loov1,zl_hw,llimwang,gubaocheng设为审查人
liu-weiliu-wei成员
5月23日 修改了pull request 的描述
liu-wei
liu-wei成员
5月23日 评论:

compile

likedislike
liu-weiliu-wei成员
5月23日 update merge request[project id: 7657293, iid: 884, commit_id: 46f0b1a9ac267f19104c7706973a306be48fe98c] virtual merging success
liu-weiliu-wei成员
5月23日 修改了pull request 的描述
CANN-robotCANN-robot成员
5月23日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
5月23日 评论:

流水线任务触发成功
任务链接 [4f50b0142b39446c81185f44f3c6b229][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Pre ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-05-23 15:27:15]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
5月23日 评论:

流水线任务触发成功
任务链接 [1c67a9004cec445d83471678892eb62c][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_checkpr ✅ SUCCESS
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS
codecheck_precommit ✅ SUCCESS >>>>> >>>>>

[2026-05-23 15:18:09]    CI执行结束

likedislike
CANN-robotCANN-robot成员
5月23日 添加了label:api-check-pass
CANN-robotCANN-robot成员
5月23日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
5月23日 添加了label:ci-pipeline-passed
liu-wei
liu-wei成员
5月25日 评论:

compile

likedislike
liu-weiliu-wei成员
5月25日 update merge request[project id: 7657293, iid: 884, commit_id: 21a7b545696c5a8d1ecefa1a3e05f5219123a927] virtual merging success
CANN-robotCANN-robot成员
5月25日 删除了label:ci-pipeline-passedapi-check-pass
CANN-robotCANN-robot成员
5月25日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
5月25日 评论:

流水线任务触发成功
任务链接 [0e96b06536324e459155c8c221c895d2][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Pre ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-05-25 09:46:50]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
5月25日 评论:

流水线任务触发成功
任务链接 [97ba779d605f4c41b9621b87fe5bae1f][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_checkpr ✅ SUCCESS
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>> >>>>>

[2026-05-25 09:37:40]    CI执行结束

likedislike
CANN-robotCANN-robot成员
5月25日 添加了label:api-check-pass
CANN-robotCANN-robot成员
5月25日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
5月25日 添加了label:ci-pipeline-passed
zl_hw成员
5月26日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
5月26日 添加了label:approved
loov成员
5月26日 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
5月26日 添加了label:lgtm
CANN-robot
CANN-robot成员
5月26日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: 张磊.
Reviewers who wrote a comment of /lgtm are: 张磊, 徐鲁威.

likedislike
CANN-robotCANN-robot成员
5月26日 关闭了关联的issue
CANN-robotCANN-robot成员
5月26日 合入了pull request