一句话:提出 MutApi,利用变异分析从正确 API 用法生成变异体并挖掘高精度 API 误用模式。
库 API 误用普遍存在,常导致崩溃与漏洞。已有静态检测工具多从大量正确用法中挖掘频繁模式,但正确样例难以获取,且“偏离频繁模式即误用”的假设过于简化,精度较低。本文提出 MutApi:将 API 误用视为正确用法的变异体,通过设计八种受常见误用特征启发的变异算子,在客户端项目上生成变异体,并收集杀死变异体的测试及相关堆栈轨迹;再根据这些信息对被杀死的变异体排序,从中发现 API 误用模式。在 16 个客户端项目、73 个 Java API 上评估,精度达 0.78,在 MuBench 上召回率 0.49,优于现有技术。
Misuses of library APIs are pervasive and often lead to software crashes and vulnerability issues. Various static analysis tools have been proposed to detect library API misuses. They often involve mining frequent patterns from a large number of correct API usage examples, which can be hard to obtain in practice. They also suffer from low precision due to an over-simplified assumption that a deviation from frequent usage patterns indicates a misuse. We make two observations on the discovery of API misuse patterns. First, API misuses can be represented as mutants of the corresponding correct usages. Second, whether a mutant will introduce a misuse can be validated via executing it against a test suite and analyzing the execution information. Based on these observations, we propose MutApi, the first approach to discovering API misuse patterns via mutation analysis. To effectively mimic API misuses based on correct usages, we first design eight effective mutation operators inspired by the common characteristics of API misuses. MutApi generates mutants by applying these mutation operators on a set of client projects and collects mutant-killing tests as well as the associated stack traces. Misuse patterns are discovered from the killed mutants that are prioritized according to their likelihood of causing API misuses based on the collected information. We applied MutApi on 16 client projects with respect to 73 popular Java APIs. The results show that MutApi is able to discover substantial API misuse patterns with a high precision of 0.78. It also achieves a recall of $0.49$ on the MuBench benchmark, which outperforms the state-of-the-art techniques.