Page 187 - 《软件学报》2026年第7期
P. 187
2872 软件学报 2026 年第 37 卷第 7 期
party modules and components developed by employing LLM-generated code. However, since LLMs are primarily trained based on open-
source code, defects and security vulnerabilities in the training code may cause potential errors in the generated code and security
problems in the software supply chain. To this end, targeted testing techniques such as EvalPlus have been proposed, but it is difficult for
these techniques to achieve the full coverage of critical paths in the supply chain due to their reliance on probability-based test case
generation, which makes it hard to uncover deep-seated logical software defects. To solve the above-mentioned problems, this study
proposes a defect detection method for LLM-generated code in software supply chains that integrates symbolic execution. This method
employs a symbolic execution mounting mechanism to automatically identify input parameters in LLM-generated code and perform
adaptation and symbolic mounting. It then guides the symbolic execution engine to conduct precise constraint analysis on the program’s
critical paths and generate efficient boundary test cases, thus detecting deep-seated logical software defects that the existing methods
struggle to detect. This study conducts experimental evaluation on the top 11 mainstream LLMs from the LMSYS Chatbot Arena by
adopting existing mainstream benchmark datasets. Experimental results show that the proposed method can more effectively detect logical
defects in LLM-generated code, reducing the average test pass rate by 3.99% to 18.98% and increasing the average test coverage by
3.31% to 8.19%. Finally, the correctness of LLM-generated code and the security of intelligent foundational software supply chains are
effectively improved.
Key words: software defect detection; supply chain security; large language model (LLM); code generation; symbolic execution
近年来, 随着大语言模型 (large language model, LLM) 在代码生成领域的快速发展 [1−6] , 以 Codex 和 [7] CodeGen [8]
等为代表的 LLM 已被广泛应用于智能化基础软件供应链中软件开发、测试、运维等各个环节, 以及系统软件、
人工智能框架软件、嵌入式领域软件等各个层次智能化基础软件的构造过程中. 研究表明, 约 40.5% 的软件开发
[9]
团队在项目中使用 LLM 生成的代码来构建模块与组件, 部分项目中由 LLM 生成的代码比例甚至超过 75% . 目
前, 软件供应链中大量第三方模块与组件均基于 LLM 生成的代码进行开发, 显著提升了基础软件的开发效率 [10,11] .
然而, 由于 LLM 主要基于大规模开源代码进行训练, 而已有研究表明, 约 84% 的开源项目中存在缺陷与安全
漏洞 [12] . 因此基于这些开源项目训练出来的 LLM 可能会无意中生成带有缺陷的代码, 导致软件供应链中许多第
三方模块与组件频繁出现功能性错误与安全问题 [13] , 进一步加剧了供应链的代码安全风险. 已有研究指出, 在大
模型生成的程序中, 约 40% 的程序存在安全漏洞 [10] , 对软件供应链安全构成严重威胁. 因此, 如何有效检测 LLM
生成代码中的潜在缺陷, 并提升基础软件供应链的安全性, 已成为当前亟需解决的关键技术难题.
为了提升对 LLM 生成代码的缺陷检测能力, 保障智能化基础软件供应链的安全性, 学术界提出了多种基于测
试用例的缺陷检测方法. HumanEval 通过结合 LLM 与传统软件测试方法, 构建了一个用于评估 LLM 生成代码
[7]
功能正确性的测试基准. 在此基础上, HumanEval-X [14] 提出了一种面向多编程语言场景的代码生成评估基准, 以更
全面地评测 LLM 在多语言环境下的代码生成能力, 从而更有效地发现生成代码中的潜在缺陷. EvalPlus [15] 则通过
结合 ChatGPT 与模糊测试 (fuzz testing) 方法, 自动批量生成测试用例, 进一步提升了对生成代码的缺陷检测能力.
然而, 现有方法大多依赖概率机制生成测试用例, 缺乏系统性的逻辑推理过程, 尤其在输入参数范围较窄或路径条
件复杂的情况下存在局限性, 难以全面覆盖 LLM 生成程序的关键路径, 从而导致深层次程序缺陷难以被有效发
现, 难以满足智能化基础软件对高可靠性和高安全性的要求.
为解决上述问题, 本文提出一种融合符号执行 (symbolic execution) 的 LLM 生成代码缺陷检测方法, 旨在系统
提升基础软件供应链中 LLM 生成代码的安全性. 该方法通过符号执行挂载算法, 自动识别并适配 LLM 生成代码
的输入参数, 实现符号变量的自动挂载. 随后, 利用符号执行技术 [16−19] , 系统推导生成程序的路径约束, 生成更具针
对性的边界测试用例. 具体而言, 本文方法首先从 LLM 生成的功能代码中提取路径约束条件, 并借助可满足性模
理论 (satisfiability modulo theory, SMT) 求解器进行求解, 进而生成能覆盖更多关键路径的边界测试用例, 从而发
现现有方法难以检测到的深层次程序缺陷, 提升 LLM 生成的软件供应链各环节代码的正确性.
以图 1 中的函数 log_message 为例, 该函数是由 LLM 生成的一段程序代码, 用于在软件运行过程中记录不同
类型的日志信息. 日志系统作为基础软件供应链中的关键组成部分, 对于软件运行状态的监控与问题定位具有重
要意义. 一个设计合理的日志系统不仅能够帮助开发人员及时掌握软件的运行状况, 还能通过日志信息快速识别
并定位潜在程序缺陷, 从而提高系统的可维护性与安全性. 在图 1 中, log_message 函数可能在软件运行期间被多

