With the rapid advancement of deep learning technologies, numerous large language models (LLMs) have been developed, achieving remarkable performance across various tasks. Nevertheless, in the field of vulnerability patch generation, previous studies still face notable limitations: (1) Insufficient context. LLM-based approaches often rely on a single vulnerable function as prompt input for generating patches, which prevents the model from utilizing adequate contextual information and limits its ability to produce accurate patches. (2) Difficulties in extracting effective fix patterns. The substantial semantic differences between various vulnerabilities result in a wide range of fix patterns. Consequently, automatically extracting effective fix patterns tailored to specific vulnerabilities becomes a significant challenge. To address this, we propose PailGen, a novel fix P attern- a ware, i n-context l earning-incorporated vulnerability patch Gen eration approach. PailGen comprises three main modules: hybrid patch retrieval module, fix pattern mining module and in-context learning-incorporated patch generation module. (1) Hybrid patch retrieval module, aims at retrieving the top- \(k\) relevant vulnerability-fix pairs from the existing codebase by combining BM25 and Dense Passage Retriever (DPR) to construct a hybrid patch retriever. (2) Fix pattern mining module, aims at extracting effective fix patterns from the relevant vulnerability-fix pairs by leveraging an automatic fix pattern mining strategy based on Abstract Syntax Tree (AST). Fix patterns are designed to analyze code changes at different levels (e.g., expression level and statement level). (3) In-context learning-incorporated patch generation module, aims at providing comprehensive contextual information for LLMs by integrating the vulnerable code, its AST, the relevant patches and the extracted fix patterns into the prompt input. Overall, PailGen delivers better demonstrations for in-context learning and provides more comprehensive semantic guidance for patch generation, enabling LLMs to effectively address vulnerabilities. We evaluate PailGen on two real-world C/C++ vulnerability datasets. The experimental results demonstrate that PailGen achieves the best performance, outperforming all baseline approaches.
Shao et al. (Mon,) studied this question.