一句话:结合代码与文档挖掘 API 规约,提升 C/C++ API 误用缺陷检测能力。
使用 API 须遵循其规约,否则可能损害功能并带来安全问题。现有 API 误用检测工具通常从现有代码库挖掘多数用法作为规约,或从自然语言文本中抽取规约;前者依赖代码库质量,后者受文本不规则性限制。本文观察到代码与文档所携带的信息可以互补,提出 APICAD,通过结合代码与文档中的规约来检测 C/C++ 的 API 误用缺陷。方法上,一方面为 API 调用构建上下文,并用基于频率的方法从中挖掘规约;另一方面使用轻量关键词与 NLP 辅助技术从文档中获取规约,最终合并规约用于缺陷检测。实验表明,APICAD 能处理多样的 API 使用语义与不同类型的 API 误用。作者在 Curl、Httpd、OpenSSL 和 Linux 内核中报告 153 个新缺陷,其中 145 个已确认,126 个已应用补丁。
Using API should follow its specifications. Otherwise, it can bring security impacts while the functionality is damaged. To detect API misuse, we need to know what its specifications are. In addition to being provided manually, current tools usually mine the majority usage in the existing codebase as specifications, or capture specifications from its relevant texts in human language. However, the former depends on the quality of the codebase itself, while the latter is limited to the irregularity of the text. In this work, we observe that the information carried by code and documents can complement each other. To mitigate the demand for a high-quality codebase and reduce the pressure to capture valid information from texts, we present APICAD to detect API misuse bugs of C/C++ by combining the specifications mined from code and documents. On the one hand, we effectively build the contexts for API invocations and mine specifications from them through a frequency-based method. On the other hand, we acquire the specifications from documents by using lightweight keyword-based and NLP-assisted techniques. Finally, the combined specifications are generated for bug detection. Experiments show that APICAD can handle diverse API usage semantics to deal with different types of API misuse bugs. With the help of APICAD, we report 153 new bugs in Curl, Httpd, OpenSSL and Linux kernel, 145 of which have been confirmed and 126 have applied our patches.