已关闭
【缺陷报告】空指针解引用 - 文件graph_utils_ex.cc - 函数GeApiWrapper_GetComputeGraphInputSize - 行号146 #270
zhangjunkai9创建于  12 天前关闭于  7 天前
zhangjunkai9
12 天前 创建

缺陷信息

缺陷类型nullptrDeref (空指针解引用)
函数GeApiWrapper_GetComputeGraphInputSize
文件autofuse/graph_metadef/graph/utils/graph_utils_ex.cc
行号146
置信度89%

缺陷描述

GeApiWrapper_GetComputeGraphInputSize 为入口函数(depth 0),第146行直接调用 af::GraphUtilsEx::GetComputeGraph(graph)->GetInputSize()。GetComputeGraph 实现(graph.cc:1194-1199)在 graph.IsValid() 为 false 时显式返回 nullptr,返回值未做空指针校验即被 ->GetInputSize() 解引用,导致空指针解引用崩溃。

事实核查

核查1模式成立:第146行 af::GraphUtilsEx::GetComputeGraph(graph)->GetInputSize() 对 GetComputeGraph 返回值直接解引用;GetComputeGraph 在 graph.IsValid() 为 false 时显式返回 nullptr(graph.cc:1194-1199 确认)。
核查2防护无效:函数内对 GetComputeGraph 返回值无任何空指针校验。
核查3函数可达:该函数为入口函数(depth 0),作为 API wrapper 供外部调用,仓内无内部调用方但作为公开 API 可达。
核查4触发条件广:graph 为外部调用方传入的入参,外部可直接传入无效 Graph(默认构造或初始化失败),外部可控输入直接到达 sink,属防御性编程缺失·触发条件广·外部可控输入直接到达 sink→confidence 0.89

数据流证据

Source(问题源头)

autofuse/graph_metadef/graph/utils/graph_utils_ex.cc:145 行 const af::Graph &graph 作为入口函数入参传入(外部调用方可传入无效 Graph)

Sink(问题爆发点)

autofuse/graph_metadef/graph/utils/graph_utils_ex.cc:146 行 af::GraphUtilsEx::GetComputeGraph(graph)->GetInputSize() 解引用可能为 nullptr 的 GetComputeGraph 返回值

传播路径:

# 文件 行号 说明
1 autofuse/graph_metadef/graph/utils/graph_utils_ex.cc 145 const af::Graph &graph 作为入口函数入参接收(无有效性校验)
2 autofuse/graph_metadef/graph/normal_graph/graph.cc 1194-1196 GraphUtilsEx::GetComputeGraph 内部 if (!graph.IsValid()) return nullptr; 当 Graph 无效时返回 nullptr
3 autofuse/graph_metadef/graph/utils/graph_utils_ex.cc 146 GetComputeGraph(graph) 返回 nullptr 后直接 ->GetInputSize() 解引用空指针(sink)

调用链

可达调用链1 起点:(entry functions) → 终点:GeApiWrapper_GetComputeGraphInputSize 深度:0

# 文件 函数 函数起始行 调用点行
1 autofuse/graph_metadef/graph/utils/graph_utils_ex.cc GeApiWrapper_GetComputeGraphInputSize 145

修复建议

size_t GeApiWrapper_GetComputeGraphInputSize(const af::Graph &graph) {
  const auto compute_graph = af::GraphUtilsEx::GetComputeGraph(graph);
  if (compute_graph == nullptr) {
    return 0U;
  }
  return compute_graph->GetInputSize();
}
likedislike
Wwangmingming成员
12 天前 将 gcw_V3YyYBt1 设为负责人
wangmingming成员
12 天前 评论:

你好,感谢建议, 后续分析处理

likedislike
Ggaoxin成员
11 天前 关联了pull request:fix: 修复 Issue #261-#276 安全加固缺陷
CANN-robotCANN-robot成员
7 天前 关闭了 issue
CANN-robotCANN-robot成员
7 天前 添加了label:resolved