通过神经符号增强静态分析发现C/C++程序中的内存泄漏
Finding Memory Leaks in C/C++ Programs via Neuro-Symbolic Augmented Static Analysis
AI总结:
提出MemHint神经符号管道,结合LLM语义理解与Z3符号推理,扩展静态分析器对自定义内存管理函数的识别和路径敏感控制流建模,在8个真实项目中发现54个内存泄漏(53个确认/修复),每个漏洞成本约1.7美元。
摘要:
内存泄漏在现实世界的C/C++软件中仍然普遍存在。CodeQL等静态分析器提供可扩展的程序分析,但经常遗漏此类错误,因为它们无法识别项目特定的自定义内存管理函数,并且缺乏路径敏感的控制流建模。我们提出MemHint,一种神经符号管道,通过结合LLM对代码的语义理解与基于Z3的符号推理来解决这两个限制。MemHint解析目标代码库,并应用LLM将每个函数分类为内存分配器、释放器或两者都不是,生成记录哪个参数或返回值拥有内存所有权的函数摘要,将分析器的内置知识扩展到malloc和free等标准原语之外。基于Z3的验证步骤根据函数的控制流图检查每个摘要,丢弃其声称的内存操作在任何可行路径上不可达的摘要。经过验证的摘要通过各自的扩展机制注入到CodeQL和Infer中。然后,Z3路径可行性过滤消除不可行路径上的警告,最后的基于LLM的验证步骤确认每个剩余警告是否为真正的错误。在总计超过360万行代码的八个真实世界C/C++项目上,MemHint检测到54个独特的内存泄漏(53个已确认/修复),每个检测到的漏洞成本约为1.7美元,而原始CodeQL检测到19个,原始Infer检测到3个。
英文摘要:
Memory leaks remain prevalent in real-world C/C++ software. Static analyzers such as CodeQL provide scalable program analysis but frequently miss such bugs because they cannot recognize project-specific custom memory-management functions and lack path-sensitive control-flow modeling. We present MemHint, a neuro-symbolic pipeline that addresses both limitations by combining LLMs' semantic understanding of code with Z3-based symbolic reasoning. MemHint parses the target codebase and applies an LLM to classify each function as a memory allocator, deallocator, or neither, producing function summaries that record which argument or return value carries memory ownership, extending the analyzer's built-in knowledge beyond standard primitives such as malloc and free. A Z3-based validation step checks each summary against the function's control-flow graph, discarding those whose claimed memory operation is unreachable on any feasible path. The validated summaries are injected into CodeQL and Infer via their respective extension mechanisms. Z3 path feasibility filtering then eliminates warnings on infeasible paths, and a final LLM-based validation step confirms whether each remaining warning is a genuine bug. On eight real-world C/C++ projects totaling over 3.6M lines of code, MemHint detects 54 unique memory leaks, all confirmed or fixed, at approximately $1.76 per detected bug, compared to 19 by vanilla CodeQL and 3 by vanilla Infer.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。