The invention discloses a method and a
system for automatically repairing context learning code vulnerabilities of a large
language model, and aims to solve the problems that invalid patches are easily generated,
vulnerability causes are misunderstood and
verification is lacked in existing LLM zero sample repairing, and a traditional method depends on annotated data or
test input. The method comprises the following steps:
processing a
vulnerability code-patch pair containing a plurality of different CWE types and a target
vulnerability code, extracting vulnerability-related codes and constructing an example
pool; an adaptive example is selected through comprehensive comparison of
semantics, lexical and
structural similarity; generating prompt words in combination with related codes and adaptive examples, driving LLMs to generate candidate patches, and outputting effective patches after
verification of multiple LLMs; the
system comprises a code
processing module, an example selection module and a patch generation and
verification module. According to the method, LLM and a large amount of annotated data do not need to be finely adjusted, the repair efficiency and accuracy are improved, the labor cost is reduced, multi-language extension is supported, and industrialization potential is achieved.