A code security defect detection method based on historical vulnerability corpus variant amplification

By using a structured query signature and reverse verification mechanism based on a historical vulnerability corpus, the problem of high false positive rate and deep defect identification across call chains in large software systems is solved, achieving efficient and continuous iteration of code security detection and improving the accuracy and capability of defect detection.

CN123179401APending Publication Date: 2026-11-27SHANGHAI SUIYUAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611674307.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-28
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies have a high false positive rate in code security testing of large software systems, difficulty in identifying deep defects across call chains, and lack a closed-loop iteration mechanism for historical vulnerabilities, resulting in the inability to continuously accumulate detection capabilities.

Method used

By acquiring a historical vulnerability corpus, we extract missing detection patterns and convert them into structured query signatures. We then use a compiler-level relational database to query candidate defects, eliminate mutually exclusive branches and false matches caused by macro expansions, verify along the call chain in reverse, generate structured verification results, and disprove candidate defects by refuting instructions. Finally, we iteratively update the signature library to improve detection capabilities.

Benefits of technology

It reduced false alarms, improved the ability to identify deep defects across call chains, enabled continuous iteration and accumulation of defect detection capabilities, and enhanced the effectiveness of detecting security defects in large codebases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123179401A_ABST
    Figure CN123179401A_ABST
Patent Text Reader

Abstract

The application discloses a code security defect detection method based on historical vulnerability corpus variant amplification, and relates to the technical field of code detection. The method comprises the following steps: extracting a missing detection mode based on the security defect records of a historical vulnerability corpus and converting the missing detection mode into a structured query signature to store the structured query signature in a signature library; relying on a compilation-level relational database to complete signature query to obtain a candidate defect result set and perform filtering; splitting the candidate defect list into independent verification units and assigning the independent verification units to independent verification agents to carry out upstream mitigation verification to obtain a structured verification result, and identifying candidate defects in a reverse falsification verification mode; sorting the structured verification result according to a preset type to obtain a sorting result, extracting common missing mode features from the confirmed real defects in the sorting result, generating new structured query signatures, supplementing the new structured query signatures to the signature library, and cyclically executing the query and verification process until an iteration stop condition is met, thereby constructing a security defect confirmation list and improving the detection effectiveness of security defects in large codes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software system security auditing and code detection technology, and in particular to a code security defect detection method based on historical vulnerability corpus variant amplification. Background Technology

[0002] In the field of security auditing of large-scale software systems, code defect detection is an important means of ensuring product quality, especially playing a key role in vulnerability discovery in low-level software such as kernel drivers and operating systems. As the size of software code grows to hundreds of thousands or even millions of lines, the calling relationships between various modules within the software become increasingly complex, and deep security vulnerabilities across functions and modules become a key focus during software auditing.

[0003] Currently, code security testing primarily employs static analysis tools, manual auditing, and AI (Artificial Intelligence) auditing assisted by large language models. Static analysis tools use fixed detection rules based on common defect classifications to identify alerts; AI auditing assisted by large language models relies on the model's semantic understanding capabilities to find code vulnerabilities.

[0004] However, static analysis tools lack an understanding of project-specific coding habits and internal application interface semantics, resulting in a high false positive rate. A large number of false reports can easily lead to auditor fatigue. Large-scale AI auditing is limited by context windows, making it difficult to effectively identify function boundary vulnerabilities that cross multiple call chains and are distributed across multiple files. At the same time, existing methods lack a mechanism to automatically derive detection capabilities from historically patched vulnerabilities, and lack a closed-loop iterative mechanism to automatically convert defect discoveries into reusable detection rules, thus preventing the continuous accumulation of detection capabilities. Summary of the Invention

[0005] This invention provides a code security defect detection method based on variant amplification of historical vulnerability corpora, in order to solve the problems of high false positive rate, difficulty in discovering deep defects across call chains due to context window limitations, and inability to accumulate detection capabilities through closed-loop iteration of historical vulnerability records.

[0006] According to one aspect of the present invention, a method for detecting code security flaws based on variant amplification of historical vulnerability corpora is provided, comprising:

[0007] Obtain the historical vulnerability corpus, read the confirmed security defect records in the historical vulnerability corpus, extract the missing detection patterns that characterize the causes of the vulnerabilities based on the vulnerability root cause information recorded in the security defect records, convert the missing detection patterns into structured query signatures and store them in the signature database.

[0008] Read the structure query signature in the signature library, perform the query operation on the pre-built compiler-level relational database, and obtain the candidate defect result set;

[0009] Remove dangerous operation matching items that cannot be executed synchronously under mutually exclusive branches from the candidate defect result set, and remove false matching nodes generated by macro expansion to obtain the candidate defect list;

[0010] The candidate defect list is split into multiple independent verification units according to functions and files. An independent verification agent is assigned to each independent verification unit, and a rebuttal instruction is issued to each independent verification agent. The rebuttal instruction enables each independent verification agent to trace back from the defect danger point along the call chain to execute the upstream mitigation verification, so as to obtain the structured verification result.

[0011] All structured verification results output by the independent verification agents are sorted according to preset types to obtain the sorting results; the preset types include at least: confirmed real defects;

[0012] Extract common missing pattern features from the defects that confirm the true defect type in the sorting results, extract new missing detection patterns based on the common missing pattern features, convert the new missing detection patterns into new structural query signatures and write them into the signature library, and return to execute the operation of reading structural query signatures in the signature library until the number of defects that confirm the true defect type produced in consecutive specified rounds of iteration is zero.

[0013] Obtain the sorting result from the last iteration, and construct a security defect confirmation list based on the sorting result.

[0014] According to another aspect of the present invention, a code security defect detection device based on historical vulnerability corpus variant amplification is provided, comprising:

[0015] The pattern extraction module is used to obtain a historical vulnerability corpus, read the confirmed security defect records in the historical vulnerability corpus, extract the missing detection patterns that characterize the causes of the vulnerabilities based on the vulnerability root cause information recorded in the security defect records, convert the missing detection patterns into structured query signatures and store them in the signature library.

[0016] The structure query module is used to read the structure query signatures in the signature library, perform query operations on the pre-built compiler-level relational database, and obtain a set of candidate defects.

[0017] The candidate elimination module is used to remove dangerous operation matching items that cannot be executed synchronously under mutually exclusive branches from the candidate defect result set, and to remove false matching nodes generated by macro expansion, so as to obtain a candidate defect list.

[0018] The reverse backtracking module is used to split the candidate defect list into multiple independent verification units according to functions and files, assign independent verification agents to each independent verification unit, and issue rebuttal instructions to each independent verification agent. The rebuttal instructions enable each independent verification agent to backtrack from the defect danger point along the call chain to execute the upstream mitigation verification and obtain the structured verification results.

[0019] The result sorting module is used to sort the structured verification results output by all independent verification agents according to preset types to obtain sorting results; wherein the preset types include at least: confirming real defects;

[0020] The round iteration module is used to extract common missing pattern features from the defects that confirm the true defect type in the sorting results, extract new missing detection patterns based on the common missing pattern features, convert the new missing detection patterns into new structural query signatures and write them into the signature library, and return to execute the operation of reading structural query signatures in the signature library until the number of defects that confirm the true defect type produced by the consecutive specified round iterations is zero.

[0021] The Confirmation List module is used to obtain the sorting result from the last iteration and to build a security defect confirmation list based on the sorting result.

[0022] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0023] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the code security defect detection method based on historical vulnerability corpus variant amplification as described in any embodiment of the present invention.

[0024] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions, the computer instructions being configured to cause a processor to execute and implement the code security defect detection method based on historical vulnerability corpus variant amplification as described in any embodiment of the present invention.

[0025] According to another aspect of the present invention, a computer program product is also provided, including a computer program that, when executed by a processor, implements the steps of the method as described in any embodiment of the present invention.

[0026] The technical solution of this invention extracts missing detection patterns from security defect records based on a historical vulnerability corpus and converts them into structured query signatures stored in a signature database. It then uses a compiler-level relational database to perform signature queries to obtain a candidate defect result set. Preliminary filtering of the candidate defect result set is achieved by removing mutually exclusive branch dangerous operation matches and macro expansion false matching nodes, reducing invalid candidates and lowering the processing pressure for subsequent verification. The candidate defect list is split into independent verification units and assigned to independent verification agents. Using rebuttal instructions, these agents are driven to trace back upstream along the call chain from the defect's danger point to obtain structured verification results. This reverse falsification verification method identifies candidate defects, reducing... Reduce false alarms; sort the structured verification results according to preset types to obtain sorting results, extract common missing pattern features from the confirmed real defects in the sorting results to generate new structure query signatures to supplement the signature library, and cyclically execute the query and verification process until the iteration stop condition is met, so that the defect detection capability can be continuously expanded with iteration, fully explore the security defects of the same source variant class in the target code, and finally construct a security defect confirmation list based on the sorting results of the last iteration, outputting a well-organized defect result. This overcomes the problems of traditional detection methods, such as the inability to reuse historical vulnerability experience, failure to detect same source variant defects, insufficient authenticity of alarms, and difficulty in discovering deep defects across call chains, and improves the detection effectiveness of security defects in large code.

[0027] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0028] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0029] Figure 1 This is a flowchart of a code security defect detection method based on historical vulnerability corpus variant amplification provided in Embodiment 1 of the present invention;

[0030] Figure 2 This is a flowchart of another code security defect detection method based on historical vulnerability corpus variant amplification provided in Embodiment 2 of the present invention;

[0031] Figure 3 This is a flowchart of another code security defect detection method based on historical vulnerability corpus variant amplification provided in Embodiment 3 of the present invention;

[0032] Figure 4 This is a schematic diagram of a code security defect detection device based on historical vulnerability corpus variant amplification according to Embodiment 4 of the present invention;

[0033] Figure 5 This is a schematic diagram of the structure of an electronic device that implements the code security defect detection method based on historical vulnerability corpus variant amplification according to embodiments of the present invention. Detailed Implementation

[0034] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0035] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0036] Example 1

[0037] Figure 1 This is a flowchart of a code security defect detection method based on variant amplification of historical vulnerability corpora provided in Embodiment 1 of the present invention. This embodiment is applicable to the detection of code security defects. This method can be executed by a code security defect detection device based on variant amplification of historical vulnerability corpora. This code security defect detection device based on variant amplification of historical vulnerability corpora can be implemented in hardware and / or software, and is generally configured in electronic devices. Figure 1 As shown, the method includes:

[0038] S110. Obtain the historical vulnerability corpus, read the confirmed security defect records in the historical vulnerability corpus, extract the missing detection pattern representing the cause of the vulnerability based on the vulnerability root cause information recorded in the security defect records, convert the missing detection pattern into a structure query signature and store it in the signature database.

[0039] In this embodiment, the historical vulnerability corpus refers to a dataset storing multiple confirmed security flaw records. Each security flaw record at least records the flaw type, the involved dangerous operation functions or code patterns, and the root cause description. The missing detection pattern refers to the extracted code feature patterns that characterize the root cause of the vulnerability. The structure query signature, derived from the missing detection pattern, can include sets of dangerous operation functions, reachability constraints, guard absence conditions, etc., and can be used to retrieve query identifiers matching the flaw in the code database. The signature library refers to a database that centrally stores various structure query signatures.

[0040] Defect type refers to the classification and identification of the vulnerability category to which the security defect belongs, such as buffer overflow, null pointer dereference, integer overflow, etc. Dangerous operation functions are program functions that are likely to trigger security defects. Code patterns are code writing styles that are likely to cause vulnerabilities, such as memory copy functions without length checks, or code that uses pointers directly without null checks. Root cause description is a textual record of the underlying fundamental reason for the vulnerability; it does not describe the vulnerability phenomenon, but rather explains why the vulnerability occurs, such as the lack of input length validation causing externally controllable data to exceed the buffer memory range.

[0041] A dangerous set of functions is a list of functions that can trigger risky behaviors. When code executes any function in this set, there is a possibility of a vulnerability being introduced. Reachability constraints are execution conditions for code paths, representing the existence of executable code paths that can reach dangerous functions. Only when a path is reachable can a vulnerability be triggered. Guards refer to security verification code (boundary checks, null pointer checks, etc.). A guard's absence occurs when the code path leading to a dangerous function lacks the necessary security verification logic.

[0042] Specifically, the system reads confirmed security defect records from the historical vulnerability corpus, extracts the root cause information of the vulnerabilities recorded in the security defect records, and extracts missing detection patterns that can characterize the causes of vulnerabilities based on the extracted root cause information. It can also combine the corresponding vulnerability remediation submission records to locate newly added security guard code to assist in refining the missing detection pattern. Then, the missing detection pattern is converted into a structured query signature containing a set of dangerous operation functions, reachability constraints, and guard missing conditions. Finally, the converted structured query signature is stored in the signature library to provide an executable query template for subsequent code defect retrieval.

[0043] In a specific example, multiple security defect records stored in the historical vulnerability corpus are read, and each record is analyzed for its defect type, dangerous operation function information, and root cause description field. The underlying root cause text information that caused the vulnerability is extracted from these records, and irrelevant vulnerability phenomenon descriptions are removed.

[0044] Obtain the code fix submission records corresponding to the vulnerability, compare the code differences before and after the fix, locate the security guard verification code added during the vulnerability fix phase, compare with the extracted vulnerability root cause information, summarize what kind of verification logic is missing in the essence of the vulnerability, and extract the missing detection pattern that characterizes the cause of the vulnerability.

[0045] The refined missing detection pattern is decomposed, and the functions that trigger security risks in the aggregation pattern are used to obtain a set of dangerous operation functions. Reachability constraints are set so that the code path can reach the dangerous operation functions. Security verification logic that should exist before reaching the dangerous operation function but is missing is defined as the guard missing condition. The above three elements are combined to generate a structure query signature that can be used for code library retrieval and matching.

[0046] S120. Read the structure query signature in the signature library, perform the query operation on the pre-built compiler-level relational database, and obtain the candidate defect result set.

[0047] In this embodiment, the compiler-level relational database refers to a relational database obtained by parsing the actual compilation process of the target code, storing call graphs, control flow graphs, data flow graphs, and abstract syntax trees. The candidate defect result set refers to the initial set of all code locations with matching structures returned after retrieving them from the compiler-level relational database using structure query signatures.

[0048] S130. Remove dangerous operation matching items that cannot be executed synchronously under mutually exclusive branches from the candidate defect result set, and remove false matching nodes generated by macro expansion to obtain the candidate defect list.

[0049] In this embodiment, the candidate defect list refers to the streamlined set of candidate defects obtained after two filtering operations: control flow tightening and node labeling exclusion. Control flow tightening involves determining code path reachability based on the control flow graph and filtering out matches that are on mutually exclusive branches or cannot be triggered simultaneously on the same execution path. Node labeling exclusion involves identifying and removing spurious code nodes generated during macro expansion.

[0050] Mutually exclusive branches refer to code branches in the code, such as if (conditional statement) or else (otherwise branch statement), that cannot be executed simultaneously. False matching nodes generated by macro expansion are code nodes generated after C or C++ macro expansion. These nodes appear to match the signature on the abstract syntax tree, but they do not belong to the original logic of the source code and can cause false positives.

[0051] During the C or C++ preprocessing stage, macros written in the source code are replaced and expanded into multiple lines of low-level code. This expansion occurs after the source code is written and before the compiler's syntax parsing. The original source code may contain only one line of macro calls, but preprocessing generates additional code statements. The compiler frontend parses the expanded code and generates an abstract syntax tree (AST). The AST records the structure of the expanded code and no longer distinguishes between the original source code and the code added by macro expansion.

[0052] The structure query signature for defect detection is designed for the original source code logic written by developers, and only cares about dangerous operations actively written by developers. The abstract syntax tree can only see the expanded code nodes, and will treat the code nodes automatically generated by macros as code written by developers. When a code sequence that happens to match the signature after macro expansion is found, structure matching will be triggered, and candidate defects will be identified. However, this matching code is not the business logic directly written and planned to be executed by the developer. It is just a byproduct of macro text replacement. The original source code logic itself does not have the vulnerability, thus generating false alarms and false positives.

[0053] Specifically, the process reads the structure query signature stored internally in the signature library, calls the query engine to retrieve information such as the call graph, control flow graph, data flow graph, and abstract syntax tree stored in the compiler-level relational database, and searches for all code locations matching the structure query signature across the entire code scope of the target code repository to obtain a candidate defect result set. Control flow tightening is performed on the candidate defect result set, using information from the database to determine whether matched dangerous operations are on the same executable code path. Dangerous operation matches that cannot be executed synchronously under mutually exclusive branches are eliminated. Then, node marking and exclusion operations are performed to identify and eliminate spurious operation nodes generated by macro expansion in C or C++ code, eliminating the structure mismatch problem caused by macro expansion, and finally obtaining a simplified candidate defect list.

[0054] In a specific example, this stage involves exhaustive detection of source instance defects across the entire repository structure, implemented using a compiler-level relational database. This is the core innovative aspect of this application. First, pre-generated structure query signatures are read from the signature library. These signatures are then input into the query engine, where a global structure matching query is performed within the pre-built compiler-level relational database.

[0055] The query engine relies on the global code structure information of the call graph and control flow graph captured during the compilation stage to search the entire code range of the target code, traverse and match all code locations that meet the defect structure characteristics, and initially obtain a set of candidate defects.

[0056] After obtaining the candidate defect result set, the result set is first subjected to control flow tightening filtering to initially eliminate false matches. This step relies on the control flow graph information built into the compiler-level relational database to accurately determine the code path reachability of each dangerous operation node and whether multiple related dangerous operations are in the same continuously executable code path. If multiple dangerous operations are distributed in mutually exclusive branches such as if and else and cannot be triggered synchronously in the same program execution flow, they are determined to be invalid structure matches and eliminated. This significantly reduces false positive samples caused by similar static structures but mutually exclusive actual paths, greatly reducing the volume of candidate defect data.

[0057] After control flow filtering, the remaining candidate results are further processed by macro expansion to remove spurious nodes, achieving a second round of precise deduplication and noise reduction. In C or C++ code compilation scenarios, error-checking macro statements are automatically expanded into multiple lines of executable code after preprocessing. A typical example is an error-checking macro (such as CHECK_ERR_AND_RETURN(mtx), which means checking for errors and returning; mtx is a mutex, a mutex lock variable), which expands into consecutive unlock and return statements. The control flow graph can easily confuse the code nodes automatically generated by macro expansion with the developer's native code nodes, incorrectly splicing them together to form seemingly compliant defect matching structures, generating a large number of invalid false alarms. For example, the control flow graph at the expression level may make excessive approximations: incorrectly connecting the unlock statement expanded by the macro with another manually written unlock statement in the subsequent code into a continuous, reachable execution path.

[0058] This application eliminates structural mismatches caused by the macro compilation mechanism by accurately marking all code operation nodes generated from macro expansion and uniformly excluding the matching items corresponding to such nodes, ultimately obtaining an accurate and noise-reduced candidate defect list.

[0059] S140. The candidate defect list is split into multiple independent verification units according to functions and files. An independent verification agent is assigned to each independent verification unit, and a rebuttal instruction is issued to each independent verification agent. The rebuttal instruction enables each independent verification agent to trace back along the call chain from the defect danger point to execute the upstream mitigation verification, so as to obtain the structured verification result.

[0060] In this embodiment, an independent verification unit refers to an independent analysis unit that includes the code range associated with a single candidate defect, obtained by splitting the candidate defect list according to function and file dimensions. An independent verification agent refers to an analysis instance that can run in parallel and is used to verify the defects of the independent verification units. A rebuttal instruction is a task instruction issued to the independent verification agent, specifying that defect verification should be conducted from the perspective of default suspicion and rebuttal. Upstream mitigation verification refers to searching upstream along the call chain from the defect's hazard point to find whether there is security mitigation logic that can offset the defect risk. The structured verification result refers to the standardized result output by the independent verification agent after completing the verification, including the defect determination conclusion and the code location information corresponding to the upstream security mitigation measures.

[0061] Specifically, the candidate defect list is split into functions and files to obtain multiple independent verification units. Each independent verification unit is assigned an independent verification agent that can run in parallel. A rebuttal instruction carrying a default suspicion and a best-efforts rebuttal stance is issued to each independent verification agent. Each independent verification agent aims to disprove the candidate defect. Based on the rebuttal instruction, it traces back from the defect danger point along the code call chain to perform upstream mitigation checks. The upstream mitigation checks perform at least reference counting or lock pairing checks, control flow mutual exclusion checks, and upstream hard-coded mitigation checks to find whether there are security mitigation measures in the upstream code. Only when a security mitigation measure is found and the corresponding file and line number are located can the candidate defect be judged as a false report. Finally, a structured verification result containing the judgment conclusion, upstream mitigation location information, etc., is output.

[0062] Reference counting or lock pairing checks verify whether resource acquisition and release operations match. Control flow mutual exclusion checks verify whether dangerous operations are in mutually exclusive code branches that cannot be executed simultaneously. Upstream hard-coded mitigation checks verify whether upstream code has fixed the input parameters of dangerous operations to safe values, eliminating defect triggering conditions.

[0063] Understandably, the conventional code defect verification logic assumes that candidate alerts are genuine vulnerabilities and seeks evidence to prove their existence (the verification approach). However, the rebuttal command issued in this embodiment instructs the independent verification agent to verify the vulnerability from a position of default suspicion and vehement rebuttal: it presupposes that the candidate defect is a false positive (false alert). The verification agent's task is not to find evidence of the vulnerability's existence, but rather to do its utmost to find evidence that can refute the candidate defect. Only by finding the upstream security mitigation code and locating the corresponding file and line number can the candidate defect be determined to be a false report. If no corresponding mitigation evidence is found, the candidate defect cannot be refuted.

[0064] In a specific example, this stage involves adversarial AI semantic verification and divide-and-conquer processing, which is the core innovation of this application. Traditional AI code auditing generally adopts a forward verification detection process, that is, actively searching for vulnerabilities by conducting code analysis, and judging a vulnerability as a vulnerability once a feature is found. This is prone to confirmation bias, leading to false alarms. This application adopts a reverse falsification verification mechanism to conduct refined and parallel adversarial semantic verification on the output candidate defect list, significantly improving the accuracy of defect judgment. That is, a rebuttal instruction is issued to the AI ​​verification agent, setting a default suspicion and making every effort to refute the position. The agent's task is not to prove the existence of the vulnerability, but to find security mitigation measures in the upstream call chain. As long as the corresponding mitigation code is found and the file line number is located, the candidate defect is overturned and judged as a false positive; if no mitigation evidence is found, the candidate defect cannot be overturned.

[0065] This phase first splits the candidate defect list according to the function and file to which the defect belongs, resulting in multiple independent verification units, thus achieving divide-and-conquer decoupling of multiple defect tasks. For each independent verification unit, the system assigns a dedicated independent verification agent, leveraging the parallel processing capabilities of multiple agents to improve overall verification efficiency. Simultaneously, each independent verification agent receives a specific rebuttal instruction, which may include the location of the candidate defect (file, line number, involved function name, etc.), a description of the matched defect type, and a clear rebuttal instruction, such as "You are a skeptical reviewer, and the default stance is that this candidate is a false positive. Please trace back along the call chain from the danger point to the source to find out if there are any upstream security mitigations you have not noticed." This establishes a core verification stance of default skepticism and vigilant rebuttal, distinguishing it from the traditional forward vulnerability verification model. It forces verification agents to default to the current candidate defect being a false positive, and to conduct subsequent verification operations with the core objective of disproving the defect. Specific files and line numbers of existing upstream security mitigations must be provided to determine if a report is false.

[0066] After receiving the task and rebuttal instructions, each independent verification agent starts from the location of the defect risk point and traces back along the code call chain to carry out a full-link upstream mitigation check, systematically searching for whether there are security mitigation mechanisms in the upstream code that can offset the defect risk. The verification process covers at least three verification dimensions, including reference counting or lock pairing checks, control flow mutual exclusion checks, and upstream hard-coded mitigation checks. Reference counting or lock pairing checks verify whether resource release operations match and whether there is a risk of repeatedly releasing the same reference, distinguishing between independent reference releases and illegal repeated release scenarios. For example, whether there is a corresponding reacquisition between two release operations, and whether the two release operations release two independent references rather than a repeated release of the same reference. Control flow mutual exclusion checks determine whether multiple dangerous operations are distributed in mutually exclusive branches and cannot be triggered on the same execution path, eliminating false defects where the static structure matches but is actually unreachable. For example, whether two dangerous operations are located in mutually exclusive error branches and success branches respectively, and whether the CFG (Control Flow Graph) path between them is actually untraversable. Upstream hard-coded mitigation checks verify whether the upper-level functions fix the input parameters of dangerous operations to safe values, eliminating vulnerability triggering conditions at the root. For example, whether the address or length parameters that dangerous operations depend on are hard-coded as safe values ​​in higher-level functions (e.g., the address is hard-coded as 0, and the length is proven bounded by the compiler), making the dangerous operations actually harmless.

[0067] The verification agent only identifies the current candidate defect as a false report when it finds effective security mitigation measures upstream and determines the specific file and line number of the corresponding code. Finally, it outputs standardized and structured verification results, completing the adversarial semantic judgment of a single candidate defect.

[0068] S150. Sort all the structured verification results output by the independent verification agents according to the preset type to obtain the sorting results.

[0069] Among them, the preset types include at least: confirming real defects.

[0070] In this embodiment, the preset type refers to a pre-defined defect classification dimension, which includes at least the identification of genuine defects.

[0071] S160. Extract common missing pattern features from the defects of confirmed true defect type in the sorting results, extract new missing detection patterns based on common missing pattern features, convert the new missing detection patterns into new structural query signatures and write them into the signature library, return to execute the operation of reading structural query signatures in the signature library, until the number of defects of confirmed true defect type produced in consecutive specified rounds of iteration is zero.

[0072] In this embodiment, the common missing pattern feature refers to the code characteristics shared by multiple confirmed real defects, representing the security guard logic that is generally missing in the project code. The newly added structural query signature is obtained based on the newly refined missing detection pattern and can be used as a query identifier for code defect retrieval.

[0073] Specifically, the structured verification results output by all independent verification agents are aggregated and sorted according to preset types to obtain sorting results. Preset types can include confirmed genuine defects, defects requiring hardware or runtime verification, and rejected false reports, etc. Common missing pattern features are extracted from the defects of the confirmed genuine defect type in the sorting results. The reasons why this type of defect was not covered by the original signature library in the previous round of detection are analyzed, and new missing detection patterns are extracted. Based on the common missing pattern features, the new missing detection patterns are converted into new structure query signatures and written into the signature library. The operation of reading structure query signatures in the signature library is returned and the code defect detection is carried out in a loop until the number of confirmed genuine defect types produced by the iteration is zero after a specified number of rounds, such as 2 rounds.

[0074] In a specific example, this stage involves confirming and sorting genuine defects. After completing multi-agent adversarial semantic verification, the system aggregates all structured verification results output by independent verification agents, categorizes and sorts them according to preset types, specifically into three categories: confirmed genuine defects, defects requiring hardware or runtime verification, and rejected false reports, forming a standardized sorting result. Simultaneously, for the confirmed security defects in the sorting results, the underlying common patterns of defect generation are summarized, and corresponding common missing pattern features are extracted. For example, all alert entries categorized as confirmed genuine defects are traversed, and the call path, root cause, and missing security guard type corresponding to each confirmed genuine defect are read one by one. By comparing the code context of multiple confirmed genuine defects, the common missing security verification logic of multiple defects is found, the common code writing characteristics of this type of defect are summarized, and the common missing pattern features are extracted.

[0075] For example, identifying similar defect characteristics in project code caused by missing security guard logic such as reference counting, lock protection, boundary checks, and null pointer checks provides a characteristic basis for subsequent defect pattern feedback updates and iterations.

[0076] Then, the process enters a closed-loop iterative stage to update the signature database for confirming genuine defects. This stage is the core innovation of this application, enabling continuous iterative accumulation of detection capabilities. This mechanism breaks away from the traditional detection model that terminates after a single scan, using the newly confirmed genuine defects discovered in each iteration as material for optimizing detection capabilities. For the selected confirmed genuine defects, the core reasons why these defects were not covered by the previous signature database are analyzed. Combined with the extracted common missing pattern features, a new missing detection pattern is obtained. Then, the new missing detection pattern is converted into a new structural query signature, and the newly added structural query signature is written into and updates the signature database.

[0077] For example, by comparing the coverage of newly confirmed defects in this round with the existing structure query signatures in the previous round of the signature database, the differences between the defects and existing signatures in terms of structural features can be located. For example, existing signatures may only limit a specific set of function names, while the functions that trigger dangerous operations in this round of new defects belong to the same category but have different function names, or existing signatures may not cover a certain upstream parameter passing path. Combining the common missing pattern features extracted earlier, functions of the same category are classified into the expanded set of dangerous operation functions, and missing parameter passing path conditions are supplemented. A new missing detection pattern that can cover this type of new defect is then summarized.

[0078] The newly refined missing detection pattern is structurally decomposed, and all dangerous operation functions involved in the pattern are collected to form an expanded set of dangerous operation functions. Reachability constraints are set so that the code path can reach the dangerous operation function. Security verification logic that should exist before reaching the dangerous operation function but is missing is defined as the guarding condition for missing. The above three elements are combined into a new structural query signature and written into the signature library for the next round of exhaustive structural query calls of the entire repository.

[0079] After completing the signature database iteration update, the defect detection process is restarted. This involves re-executing the entire process of reading the signature database structure to query signatures, querying the entire repository structure, filtering candidate defects, and performing adversarial AI semantic verification. This allows for a deeper re-discovery of homologous variant defects. This iterative process continues in a loop until no new confirmed defects are generated during a specified number of iterations. At this point, it is determined that all similar and homologous defects in the current code repository have been sufficiently discovered, the iteration process terminates, and a complete and well-organized list of confirmed security defects is output.

[0080] S170. Obtain the sorting result obtained from the last iteration, and construct a security defect confirmation list based on the sorting result.

[0081] In this embodiment, the sorting result is a set of results obtained by summarizing the structured verification results of all independent verification agents and sorting them according to preset types. The security defect confirmation list is a summary list of defects built after the process converges and terminates. Each defect entry in the list includes the complete call path, triggering conditions, and a description of the exploitation scenario.

[0082] Specifically, during each iteration, the number of newly confirmed real defects discovered in that iteration is continuously recorded. When the number of newly confirmed real defects produced in a specified number of consecutive iterations is zero, it is determined that defect mining has reached convergence under the current code repository and signature library configuration conditions, and the iterative detection process is stopped. The sorting result obtained from the last iteration is obtained, and the confirmed real defect information is filtered based on the sorting result. A security defect confirmation list is compiled and constructed. Each defect entry in the list contains the corresponding complete call path, triggering conditions, and exploitation scenario description, which serves as the final output of the entire detection method.

[0083] The overall input of this embodiment includes the complete compilation environment and source code of the target code repository, as well as a historical vulnerability corpus containing multiple confirmed security defect records. Each security defect record records at least the defect type, the dangerous operation function or code pattern involved, and a root cause description. The final output is a list of confirmed security defects that has undergone adversarial verification and hierarchical sorting. Each defect in the list is accompanied by a complete call path, triggering conditions, and exploitation scenario description, ensuring that the defect results are well-organized and verifiable.

[0084] The technical solution of this invention extracts missing detection patterns from security defect records based on a historical vulnerability corpus and converts them into structured query signatures stored in a signature database. It then uses a compiler-level relational database to perform signature queries to obtain a candidate defect result set. Preliminary filtering of the candidate defect result set is achieved by removing mutually exclusive branch dangerous operation matches and macro expansion false matching nodes, reducing invalid candidates and lowering the processing pressure for subsequent verification. The candidate defect list is split into independent verification units and assigned to independent verification agents. Using rebuttal instructions, these agents are driven to trace back upstream along the call chain from the defect's danger point to obtain structured verification results. This reverse falsification verification method identifies candidate defects, reducing... Reduce false alarms; sort the structured verification results according to preset types to obtain sorting results, extract common missing pattern features from the confirmed real defects in the sorting results to generate new structure query signatures to supplement the signature library, and cyclically execute the query and verification process until the iteration stop condition is met, so that the defect detection capability can be continuously expanded with iteration, fully explore the security defects of the same source variant class in the target code, and finally construct a security defect confirmation list based on the sorting results of the last iteration, outputting a well-organized defect result. This overcomes the problems of traditional detection methods, such as the inability to reuse historical vulnerability experience, failure to detect same source variant defects, insufficient authenticity of alarms, and difficulty in discovering deep defects across call chains, and improves the detection effectiveness of security defects in large code.

[0085] Example 2

[0086] Figure 2 This is a flowchart of another code security defect detection method based on historical vulnerability corpus variant amplification provided in Embodiment 2 of the present invention. This embodiment is a refinement of the above embodiment's step of "extracting a missing detection pattern characterizing the cause of a vulnerability based on the vulnerability root cause information recorded in the security defect record, converting the missing detection pattern into a structure query signature and storing it in a signature library." Figure 2 As shown, the method includes:

[0087] S210. Obtain the historical vulnerability corpus, read the confirmed security defect records in the historical vulnerability corpus, and retrieve the corresponding vulnerability remediation submission records based on the security defect record association information.

[0088] In this embodiment, the vulnerability fix submission record refers to the code change record submitted in the code version management tool to fix the corresponding security flaw.

[0089] S220. Locate the newly added security guard code from the vulnerability remediation submission record and extract the missing detection pattern that characterizes the cause of the vulnerability.

[0090] In this embodiment, the security guard code is verification code added by the developer to avoid vulnerability risks, such as reference counting, lock protection, boundary judgment, null pointer judgment, etc.

[0091] S230. Convert the missing detection mode into a structure query signature and store it in the signature database.

[0092] Specifically, the system reads security defect records from the historical vulnerability corpus, parses the defect type, dangerous operation functions, corresponding code files and line numbers recorded in the records, retrieves the corresponding vulnerability remediation submission records based on the associated information of the security defect records, compares the code differences before and after the remediation to locate the newly added security guard code, and extracts a missing detection pattern that characterizes the cause of the vulnerability. This missing detection pattern represents the code feature that lacks a corresponding security guard before the dangerous operation point. Then, the missing detection pattern is converted into a structured query signature containing a set of dangerous operation functions, reachability constraints, and guard missing conditions, and stored in a signature library for subsequent retrieval of matching similar code defects in the compiler-level relational database.

[0093] For example, read a security defect record of a double release vulnerability from the historical vulnerability corpus, parse the defect type, dangerous release function, and defect code location corresponding to the record, retrieve the code fix submission record corresponding to the vulnerability, compare the differences between the code before and after the fix to find the newly added reference count and obtain the security guard code, extract the missing detection pattern of missing reference count verification logic before the dangerous release operation, decompose the pattern to obtain the set of dangerous operation functions, code path reachability constraints, and guard missing conditions, combine them to generate the corresponding structure query signature and save it to the signature library for subsequent full repository code defect retrieval.

[0094] In a specific example, this stage involves structural querying and signature extraction of historical vulnerability corpora. This stage reads each confirmed security flaw record from the historical vulnerability corpus, parsing it to obtain the flaw type (e.g., deadlock, use after free (UAF), double-free, reference counting leak, etc.), the dangerous operation functions involved (e.g., a specific lookup function returns an unreferenced pointer that is then dereferenced by the caller without protection), and the corresponding code file and line number information. Based on the association information of the security flaw record, the corresponding vulnerability remediation submission record is retrieved.

[0095] By comparing the code differences before and after the vulnerability remediation submission records, we can locate the security guard code added during the vulnerability remediation process. For example, adding reference counting logic after function calls, adding lock protection, setting numerical upper bound checks, or adding null pointer checks, etc., can help us extract the missing detection pattern that characterizes the cause of the vulnerability. The meaning of this missing detection pattern is that there is a lack of corresponding security guard logic before the dangerous operation point in the code.

[0096] The extracted defect detection patterns are converted into structured query signatures, which contain the following components: a set of dangerous operation functions, reachability constraints, and guard absence conditions. The set of dangerous operation functions is used to collect operation functions with security risks; the reachability constraints determine whether two dangerous operations are sequentially reachable on the same control flow path; and the guard absence conditions indicate that there are no specified security guard function calls between two dangerous operations. After conversion, the generated structured query signatures are stored in a signature library to obtain reusable defect retrieval signatures for subsequent code defect matching queries in compiler-level relational databases.

[0097] Optionally, based on the above embodiments, the vulnerability remediation submission record includes the original defective code snippet, the newly added security guard code, submission comments, and modified file path information.

[0098] In this embodiment, the original defective code snippet is the code content with a security flaw before the vulnerability was patched. The newly added security guard code is verification code added during the vulnerability patching process to eliminate vulnerability risks. The submission comment is the text describing the code changes filled in by the developers. The modified file path information is the storage path corresponding to the source code file where the code change occurred.

[0099] Specifically, the system reads security defect records from the historical vulnerability corpus, retrieves corresponding vulnerability fix submission records stored in the version control system but not in the historical vulnerability corpus, and includes the original defect code snippet, newly added security guard code, submission comments, and modified file path information. Based on these fix submission records, the system extracts missing detection patterns, converts the new detection patterns into structured query signatures, and writes them into the signature library. The updated signature library is then used to re-execute Phase 3, and a new round of exhaustive search of the target code repository is conducted.

[0100] Version control systems are code management tools used to record all code modifications and changes submitted.

[0101] By configuring vulnerability fix submission records to include the original defective code snippet, newly added security guard code, submission comments, and modified file path information, the code change details before and after the vulnerability fix, as well as the fix instructions marked by the developers, can be completely preserved. This facilitates the accurate location of newly added security guard code from the differences in code changes, reliably extracts missing detection patterns that characterize the cause of the vulnerability, and provides sufficient and accurate original code evidence for the subsequent generation of structure query signatures. This avoids the pattern extraction bias caused by relying solely on the textual description of the vulnerability and improves the ability of the generated structure query signature to match and identify similar defects.

[0102] S240. Read the structure query signature in the signature library, perform the query operation on the pre-built compiler-level relational database, and obtain the candidate defect result set.

[0103] S250. Remove dangerous operation matching items that cannot be executed synchronously under mutually exclusive branches from the candidate defect result set, and remove false matching nodes generated by macro expansion to obtain the candidate defect list.

[0104] S260. The candidate defect list is split into multiple independent verification units according to functions and files. An independent verification agent is assigned to each independent verification unit, and a rebuttal instruction is issued to each independent verification agent. The rebuttal instruction enables each independent verification agent to trace back along the call chain from the defect danger point to execute the upstream mitigation verification, so as to obtain the structured verification result.

[0105] S270. Sort all the structured verification results output by the independent verification agents according to the preset types to obtain the sorting results. Among them, the preset types include at least: confirming real defects.

[0106] S280. Extract common missing pattern features from the defects of confirmed true defect type in the sorting results, extract new missing detection patterns based on the common missing pattern features, convert the new missing detection patterns into new structural query signatures and write them into the signature library, return to execute the operation of reading structural query signatures in the signature library, until the number of defects of confirmed true defect type produced in consecutive specified rounds of iteration is zero.

[0107] S290. Obtain the sorting result obtained from the last iteration, and construct a security defect confirmation list based on the sorting result.

[0108] The technical solution of this invention retrieves the vulnerability repair submission records associated with the security defect records, locates the newly added security guard code from the repair submission records, extracts the missing detection pattern that characterizes the cause of the vulnerability, and then converts the missing detection pattern into a structure query signature and stores it in the signature library. Since the newly added security guard code in the vulnerability repair submission records directly corresponds to the protection logic that was originally missing in the vulnerability, extracting the missing detection pattern based on this can accurately reproduce the defect formation mechanism of historical vulnerabilities, and generate a structure query signature that fits the actual code characteristics of the project. This can transform the repaired historical vulnerabilities into reusable detection credentials, avoid the historical repaired security defects being idle as archived data, realize the effective reuse of historical vulnerability experience, provide a reliable pattern basis for subsequent batch retrieval of similar and homologous variant defects in the code repository, and improve the accuracy of subsequent defect pattern matching.

[0109] Example 3

[0110] Figure 3This is a flowchart of another code security defect detection method based on historical vulnerability corpus variant amplification provided in Embodiment 3 of the present invention. This embodiment is a refinement of the code security defect detection method based on historical vulnerability corpus variant amplification in the above embodiments. Figure 3 As shown, the method includes:

[0111] S310. Obtain the historical vulnerability corpus, read the confirmed security defect records in the historical vulnerability corpus, extract the missing detection pattern representing the cause of the vulnerability based on the vulnerability root cause information recorded in the security defect records, convert the missing detection pattern into a structure query signature and store it in the signature database.

[0112] S320: Obtain the complete compilation environment and source code of the target code repository, and capture the command line parameters corresponding to each compilation unit through compiler tracing operations.

[0113] In this embodiment, a compilation unit is a code unit that independently participates in the compilation process during source code compilation. Compiler tracing operations are operations that monitor the compilation execution process and collect compilation-related parameter information. Command-line arguments are configuration information passed to the compiler during compilation, which may include header file paths, macro definitions, compiler flags, etc.

[0114] S330. Obtain the source code corresponding to each compilation unit from the source code of the target code repository, and combine it with the corresponding command line parameters to perform parsing processing on each compilation unit by simulating the compiler front end to obtain the structured extraction file.

[0115] In this embodiment, the simulated compiler front-end replicates the parsing logic of the compiler front-end, performing lexical and syntactic analysis on the source code. The structured extraction file is a standardized structured code information file output after the source code is parsed.

[0116] S340. Import all structured extracted files into a relational database to obtain a compiled-level relational database.

[0117] Among them, the compiler-level relational database includes call graphs, control flow graphs, data flow graphs, and abstract syntax trees.

[0118] In this embodiment, the abstract syntax tree is a tree-shaped data structure that represents the syntax structure of the source code. The control flow graph is a graph structure that represents the jump paths during code execution.

[0119] Specifically, before reading the structure query signature in the signature library, the complete compilation environment and source code of the target code repository are obtained. The command-line parameters corresponding to each compilation unit are captured through compiler tracing operations. The source code corresponding to each compilation unit in the target code repository is read. Combined with the corresponding command-line parameters, the compiler front-end is simulated to perform parsing processing on each compilation unit to obtain structured extraction files. All structured extraction files are imported into a relational database to build a compilation-level relational database containing call graphs, control flow graphs (CFG), data flow graphs, and abstract syntax trees. By performing cross-source file joint query operations, pattern matching is achieved across any call relationship connection position in multiple source files.

[0120] Cross-source file join queries are performed in a compiler-level relational database and can retrieve queries from related locations across multiple source files.

[0121] For example, the source code of the target kernel code repository is obtained and the compilation configuration environment is collected. During the compilation and execution process, compiler tracing is enabled, and command-line parameters such as header file paths, macro definitions, and compiler flags corresponding to each compilation unit are collected. The source code corresponding to each compilation unit is read, and the collected command-line parameters are used to simulate the compiler front end to perform syntax parsing using a database building tool, generating structured extraction files. All structured extraction files are then imported into a relational database in batches to generate a compiler-level relational database containing call graphs, control flow graphs, data flow graphs, and abstract syntax trees. Subsequently, cross-source file joint queries are performed in this database to complete defect pattern matching of cross-source file call chain locations.

[0122] In a specific example, this stage involves building a compiler-level relational database, which provides underlying code data support for subsequent full-repository defect pattern retrieval.

[0123] First, obtain the complete compilation environment and source code of the target code repository. Then, capture the complete command-line arguments corresponding to each compilation unit through compiler tracing operations. The command-line arguments include header file paths, macro definitions, and compiler flags, ensuring that the subsequent parsing process completely restores the actual compilation context of the code.

[0124] The source code corresponding to each compilation unit is obtained from the source code of the target code repository. Combined with the captured corresponding command line parameters, the database building tool simulates the compiler front end to perform parsing processing on each compilation unit, generating a structured extraction file (such as Tuple Relation AttributeProperty, TRAP file) containing an abstract syntax tree, control flow graph, and data flow graph. This parsing process retains context information such as macro expansion and conditional compilation branches during the compilation process, avoiding source code parsing distortion caused by being out of the compilation environment.

[0125] In this context, Tuple represents a tuple, which is the most basic unit of record in a TRAP file; Relation represents a relationship, used to describe the connection between code nodes (parent-child, call, data flow, etc.); Attribute represents a characteristic, which is inherent information of a single code node; and Property represents an attribute, which is the value information attached to the relationship between nodes.

[0126] The structured extraction files corresponding to all compilation units are imported into a relational database to form a compilation-level relational database. This database internally stores complete call graphs, control flow graphs, data flow graphs, and abstract syntax trees. Relying on the joint storage of multi-graph structures, it supports joint query operations across source files and functions, enabling structure queries to span any position where call relationships are connected in multiple source files, and achieving defect pattern matching across the entire repository.

[0127] S350. Read the structure query signature in the signature library, perform the query operation on the pre-built compiler-level relational database, and obtain the candidate defect result set.

[0128] S360. Remove dangerous operation matching items that cannot be executed synchronously under mutually exclusive branches from the candidate defect result set, and remove false matching nodes generated by macro expansion to obtain the candidate defect list.

[0129] S370. The candidate defect list is split into multiple independent verification units according to functions and files. An independent verification agent is assigned to each independent verification unit, and a rebuttal instruction is issued to each independent verification agent. The rebuttal instruction enables each independent verification agent to trace back along the call chain from the defect danger point to execute the upstream mitigation verification, so as to obtain the structured verification result.

[0130] S380. Sort all the structured verification results output by the independent verification agents according to the preset types to obtain the sorting results. Among them, the preset types include at least: confirming real defects.

[0131] Optionally, based on the above embodiments, the preset type also includes: rejected false reports; correspondingly, the defect of the rejected false report type is determined by the independent verification agent when it finds that there are security mitigation measures upstream and provides the specific documents and line numbers corresponding to the security mitigation measures.

[0132] In this embodiment, the security mitigation measure is the security guard code in the code used to prevent the defect from being triggered.

[0133] Specifically, the preset type includes rejected false reports. The independent verification agent conducts verification based on the default skepticism and the best efforts to refute the claims. When the independent verification agent finds that there are security mitigation measures upstream and provides the specific documents and line numbers corresponding to the security mitigation measures, the corresponding candidate defects are judged as rejected false reports.

[0134] By setting rejected false reports as preset classification types and restricting the independent verification agent to only classify candidate defects as rejected false reports when upstream security mitigation measures are found and the specific file and line number corresponding to the security mitigation measures are located, the independent verification agent can be constrained from arbitrarily rejecting candidate defect alerts. This reduces the probability of false report misjudgment, decreases the risk of confirmed defects being incorrectly removed, ensures the traceability of defect verification results, and allows for rapid review of the judgment basis of false reports based on the recorded file and line number, thereby improving the credibility of the entire code security defect detection results.

[0135] Optionally, based on the above embodiments, the preset type further includes: defects requiring hardware or runtime verification; the structured verification result includes a judgment conclusion; the judgment conclusion is a confirmed genuine defect, a rejected false report, or a defect requiring hardware or runtime verification; the structured verification result for the confirmed genuine defect type also includes a revised severity rating, triggering conditions, and exploitation scenario description; the structured verification result for the rejected false report type also includes the specific documents and line numbers of upstream security mitigation measures.

[0136] In this embodiment, the judgment conclusion is the qualitative result given by the independent verification agent on the candidate defect, which may include confirmed genuine defects, rejected false reports, and defects requiring hardware or runtime verification. The revised severity rating is the defect danger level obtained by the independent verification agent through evaluation and adjustment. The triggering condition is the code execution condition that must be met for the defect to be triggered and executed. The exploitation scenario description is the environment and operational situation under which the defect can be exploited by attackers. The specific documents and line numbers of the upstream security mitigation measures are the source code locations corresponding to the security guard code that can negate the establishment of the defect.

[0137] Specifically, the structured verification results include a judgment conclusion, which is divided into confirmed genuine defects, rejected false reports, and defects requiring hardware or runtime verification. The preset type includes defects requiring hardware or runtime verification. The structured verification results corresponding to confirmed genuine defects include a revised severity rating, triggering conditions, and exploit scenario description. The structured verification results corresponding to rejected false reports include the specific documents and line numbers of upstream security mitigation measures. For candidate defects that cannot be qualitatively determined by static code analysis alone, they are marked as defects requiring hardware or runtime verification.

[0138] For example, after the independent verification agent completes the verification of candidate defects, it outputs structured verification results and makes a qualitative judgment on the candidate defects obtained from the verification. If the static evidence fully confirms the existence of the defect, it is marked as a confirmed real defect and the adjusted defect severity level, code triggering conditions and vulnerability exploitation scenario are filled in. If the upstream security mitigation code is found, it is marked as a rejected false report and the file and line number of the security mitigation code are recorded. If it is not possible to determine whether the defect can be triggered in the actual environment based solely on the static code information, it is marked as a defect that needs to be confirmed by hardware or runtime.

[0139] For example, compare the control flow and data flow information corresponding to the candidate defects, confirm that there is no corresponding security guard code on the dangerous operation path, mark the candidate defect as a confirmed real defect when the static evidence is complete and sufficient, read the call chain and memory operation type corresponding to the defect, adjust the severity level of the defect according to the degree of harm that the vulnerability can cause, sort out the code execution conditions that can reach the dangerous operation, and summarize the vulnerability exploitation scenarios that attackers trigger the vulnerability in combination with the code running environment and complete the filling.

[0140] Read the control flow branch and hardware-related interface call information corresponding to the candidate defect, check the static code information in the existing compiler-level relational database, and when the triggering condition of the code defect depends on the hardware register state or the dynamic variable value at runtime, and it is impossible to determine whether the defect can be actually triggered by static code information such as abstract syntax tree, control flow graph, and data flow graph, mark the candidate defect as a defect that needs to be confirmed by hardware or runtime.

[0141] By categorizing judgment conclusions into three preset types—confirmed genuine defects, rejected false reports, and defects requiring hardware or runtime verification—and recording corresponding information in the structured verification results for each type, the system allows for refined differentiation of candidate defects. Defects that cannot be qualitatively identified through static analysis are categorized separately, preventing misjudgments of such defects as confirmed genuine defects or false reports. Furthermore, each type of verification result is accompanied by verifiable supporting information, facilitating auditors' quick access to the judgment basis, reducing the workload of manual review, and improving the completeness and traceability of code security defect detection results.

[0142] S390. Extract common missing pattern features from the defects of confirmed true defect type in the sorting results, extract new missing detection patterns based on the common missing pattern features, convert the new missing detection patterns into new structural query signatures and write them into the signature library, return to execute the operation of reading structural query signatures in the signature library, until the number of defects of confirmed true defect type produced in consecutive specified rounds of iteration is zero.

[0143] S3100. Obtain the sorting result obtained from the last iteration, and construct a security defect confirmation list based on the sorting result.

[0144] Furthermore, based on the above embodiments, the method further includes:

[0145] During the process of refuting the instructions to make each independent verification agent trace back along the call chain from the defect danger point to execute the upstream mitigation verification, latent defects are identified and marked and saved; among them, latent defects are defects that are masked by the current running conditions but can be activated after subsequent code modifications;

[0146] Latent defects are marked as risk items that trigger refactoring, which serves as a reminder to take precautions against risks during subsequent code modification and refactoring phases.

[0147] In this embodiment, a latent defect is a code defect that cannot be triggered at present due to code execution conditions, but can be activated after code modification and refactoring. The refactoring trigger risk item is a tag set for latent defects to alert developers that there is a risk of defect activation during the code refactoring phase.

[0148] Specifically, during the process of the independent verification agent tracing back along the call chain from the defect danger point according to the rebuttal instruction to carry out upstream mitigation verification, it identifies and marks latent defects that are masked by the current running conditions but can be activated after code modification. These latent defects are marked as refactoring trigger risk items, prompting developers to take risk prevention measures in the subsequent code modification and refactoring stages. These latent defects include defects that are masked by accidental conditions, such as guard condition errors causing unreachable paths or functions being unreachable code.

[0149] For example, after receiving a rebuttal instruction, the independent verification agent traverses the call chain upwards from the defect danger point to check the upstream security mitigation code. The search reveals that some code paths corresponding to defects cannot be executed due to incorrect guard judgment conditions, or the corresponding functions are unreachable code. In the current environment, the defect cannot be triggered, but once the developer modifies the relevant branch code, the defect will be activated. Identify these latent defects and mark them as refactoring trigger risk items to remind developers to pay attention to the corresponding security risks when modifying the source code.

[0150] By simultaneously identifying and marking latent defects that are currently masked by runtime conditions but can be activated after code modification during the upstream mitigation verification process conducted by an independent verification agent tracing back along the call chain from the defect danger point based on the rebuttal instruction, these latent defects are marked as refactoring trigger risk items. This allows for the discovery of potential security vulnerabilities that are not currently exposed but are easily activated during code refactoring within the main process of static defect detection. This avoids the limitation of conventional defect detection, which only focuses on currently triggerable vulnerabilities, and provides developers with early warnings of risk points during the code refactoring stage. It guides developers to add targeted protection logic in subsequent code modification processes, preventing latent defects from being accidentally activated during code refactoring operations and improving the security of code during long-term iteration.

[0151] In a specific example, the purpose of this invention is to provide a code security defect detection method based on the amplification of variants of historical vulnerability corpora. By leveraging project-specific structure query signature automatic extraction, exhaustive search of compiler-level relational databases, adversarial AI semantic verification divide-and-conquer architecture, and closed-loop iterative techniques for confirming real defects and updating the signature library, this method solves the problems of high false positive rate, blind spots in cross-function detection, inability to reuse historical vulnerability corpora, lack of adversarial mechanisms in defect verification, and inability to continuously accumulate detection capabilities in existing technologies.

[0152] The code security defect detection method based on variant amplification of historical vulnerability corpora proposed in this invention adopts a four-stage divide-and-conquer architecture of signature extraction, mechanical exhaustive search, adversarial verification, and closed-loop iteration. The overall system architecture includes two types of inputs: input A is a code repository that stores hundreds of thousands of lines of C language code; input B is a historical vulnerability corpus that stores hundreds of records of fixed defects.

[0153] The entire process is divided into six stages. Stage 1 is the construction of a compiler-level relational database, and Stage 2 is the extraction of signatures from historical vulnerabilities to structural queries. Both of these belong to the preprocessing stage. Stages 3, 4, and 6 are the core innovation stages.

[0154] Phase three involves exhaustively enumerating all instances of the same source structure in the relational database, using control flow tightening and macro expansion to reduce a large number of candidate results to a minimum number of candidate defects. Phase four is a divide-and-conquer phase of adversarial AI semantic verification, distributing multiple candidate defects to multiple independent verification agents for parallel processing. Each verification agent maintains a default rejection stance, and can only complete the judgment and output the results of confirmed genuine defects, rejected false reports, or defects requiring hardware or runtime verification when the corresponding file and line number of the upstream mitigation measures are located. Phase five completes the collection and sorting of confirmed genuine defects. Phase six implements a closed-loop iteration of updating the signature library with confirmed genuine defects, converting the new defects detected in this round into new structure query signatures, and sending them back to phase three to start a new round of full-repository retrieval.

[0155] The system ultimately outputs a sorted list of confirmed defects, including the complete call path, triggering conditions, and exploitation scenarios. Each scan produces results independently, and newly detected confirmed defects are fed back to update the signature database, enabling the next round of retrieval to cover more similar defects. The iterative process converges when no new confirmed defects are added for two consecutive rounds.

[0156] In a specific example, regarding a particular historical defect:

[0157]

[0158] This code example demonstrates a use-after-free (UAF) vulnerability in the kernel: within the `handle_ioctl` function, `dev_context_get` only performs an IDR lookup to obtain the `ctx` pointer, without calling `kref_get` to increment the `ctx` object's reference count. This allows other threads to concurrently release the `ctx` object. Subsequent code continues to dereference the `ctx` pointer, accessing `ctx->bo_mgr` and `ctx->bo_mgr->field`, triggering the use-after-free vulnerability. The corresponding fix is ​​to call `dev_context_ref_by_ctx_id` to increment the object's reference count and then execute `unref` to release the reference after use, preventing the object from being prematurely released by other threads.

[0159] The structure query signature extraction and augmentation process in this embodiment of the invention can be as follows: extract the set of dangerous operation functions, reachability constraints, and guard absence conditions from the historical defect code; execute the structure query signature extraction operation in phase two to generate the corresponding structure query signature. For example:

[0160]

[0161] This section describes the structured query signature. First, the `bareLookup` predicate is defined to match call nodes for target functions with names like `dev_context_get` and `dev_bo_get_with_handle`. Then, all function call nodes are queried, filtering for those that match the `bareLookup` predicate and do not contain `kref_get` reference count increment operations on the same code execution path. This identifies candidate defective code locations that only retrieve object pointers but do not increment object reference counts, posing a risk of concurrent release leading to reuse after release. The predicate is a logical judgment unit in the query statement used to define the code node matching rules, describing the code characteristics to be searched and returning a set of code nodes that meet the conditions.

[0162] Then, in Phase Three, the structure query is executed within the compiler-level relational database. Relying on the code information stored in the database, all instances of the same structure are mechanically retrieved, achieving cross-file, cross-function, and cross-call level matching retrieval. All candidate defects that conform to the structure pattern are exhaustively obtained across the entire repository. The retrieval strategy adopts a lenient matching strategy, following the principle of prioritizing the detection rate of confirmed true defects and allowing for candidate alarm redundancy. Finally, multiple candidate defects with the same structure are output and handed over to the subsequent adversarial AI semantic verification divide-and-conquer phase for further verification.

[0163] For example, the candidate defect results obtained by exhaustively searching for homogeneous instances of the entire repository structure can be: mod_info. c:NNNget_attribution->dev_context_get->deref ctx->bo_mgr <- HIGH, CONFIRMED;

[0164] dev_ioctl.c: NNN svc->dev_uuid_get_data-> After releasing the lock, dereference entry <-UAF, CONFIRMED;

[0165] dev_ip_x.c:XXX dev_context_get->dereferences ctx->msg_mgr without ref <- known defects;

[0166] mod_info.c: NNN mod_process_get_by_pid->Error path leak kref <- resource leak.

[0167] Each record indicates the source file containing the defect, its line number, complete code call chain, defect type, and judgment status. The first record, located in `mod_info.c`, contains a defect where `dev_context_get` (the device context acquisition function, which only finds and returns a pointer to the device context object `ctx` and does not automatically increment the object's kref reference count; this is the function used for predicate matching mentioned earlier) dereferences `ctx->bo_mgr` (derefers to the `ctx` pointer and reads its internal `bo_mgr` member; if the `ctx` object has been released by another thread, this dereferencing operation will trigger a use-after-free vulnerability). This record is marked as high-risk and confirmed as a genuine defect (HIGH, CONFIRMED). The second record, located in `dev_ioctl.c`, dereferences `entry` after releasing the lock, belonging to the use-after-free type defect, and is judged as a confirmed genuine defect (UAF, CONFIRMED). The third record, located in `dev_ip_x.c`, calls `dev_context_get`. The dereference operation was performed without increasing the object reference count, which is a known existing defect; the fourth record is located in the mod_info.c file, where the reference count was not released on the error code branch, which is determined to be a resource leak defect.

[0168] NNN / XXX represents source code line number placeholders. `get_attribute` is the function call name in the example code, which retrieves attribute information. In this example call chain, it is the starting call node, followed by the `dev_context_get` function call. `svc` is the system service entry function. `dev_uuid_get_data` is the function for reading device UUID (Universally Unique Identifier) ​​data. In the example, this function contains code logic that continues to dereference the entry pointer after releasing the lock, which will trigger a Use-After-Free (UAF) vulnerability.

[0169] `dev_context_get` is the device context acquisition function. It only retrieves the pointer to the device context object and does not automatically increment the object reference count (kref). This is the target function for the `bareLookup` predicate matching. `ctx->msg_mgr` accesses the `msg_mgr` member variable within the `ctx` device context structure. When the `ctx` pointer is retrieved, no reference counting protection is added. If another thread accesses this member after `ctx` has been released, it will trigger a User-Avoid (UAF) vulnerability.

[0170] mod_process_get_by_pid is a function that retrieves a process object based on its process identifier. In the example, the function call path contains a reference counting logic error, which leads to a resource leak.

[0171] Kref (Kernel Reference) is used to manage the lifecycle of kernel objects. Calling kref_get increases the reference count and calling kref_put decreases the reference count. The kernel will only release the object memory when the reference count reaches zero. Without kref protection, concurrent release UAF vulnerabilities may occur.

[0172] In a specific example, the adversarial AI semantic verification divide-and-conquer process of this invention, which belongs to the core innovation stage of this invention, may specifically include:

[0173] Phase 3 outputs multiple candidate defects, which are then distributed in parallel to multiple independent verification agents. Each candidate defect is assigned to an independent verification agent for verification. Upon receiving a candidate defect, each verification agent follows a default skepticism and best-efforts rebuttal approach, tracing back along the call chain from the defect's danger point and sequentially performing three types of upstream mitigation checks. These checks include reference count and lock pairing, control flow branch mutual exclusion, and hard-coded security mitigation conditions.

[0174] After completing the verification, the verification agent outputs a structured judgment conclusion, which is divided into three categories: confirming the existence of a real defect, rejecting the defect, and requiring hardware or runtime confirmation. When the verification agent issues a rejection conclusion, it must record the file and line number corresponding to the upstream security mitigation measures as the basis for the judgment. After verifying all candidate defects, the output results of each verification agent are summarized to generate a ranked list of confirmed real defects. This mechanism requires that the verification agent cannot arbitrarily reject candidate defects; only by retrieving the specific location of the upstream security mitigation code can the candidate defect be marked as a rejected false report, effectively reducing the probability of false positives in defect detection.

[0175] In actual operation, this process can perform fine-grained qualitative differentiation of batch candidate defects, individually mark defects for which static code information is insufficient to complete the judgment and which require further verification by hardware or runtime information, and completely retain the judgment basis corresponding to various defects to ensure that the audit results are reviewable.

[0176] In a specific example, the closed-loop iterative process of this invention can be as follows: The system initiates the first round of scanning, sequentially performing exhaustive structural queries and adversarial AI semantic verification, detecting and confirming multiple code defects; from the newly confirmed real defects in this round, the corresponding structural patterns are extracted, new structural query signatures are generated and written into the signature database, and the next round of scanning is initiated. Subsequent rounds of scanning reuse the updated signature database for further retrieval, and newly detected confirmed real defects are continuously fed back to expand the signature database, enabling the next round of retrieval to cover more similar code defects, and the number of newly confirmed real defects obtained in each iteration gradually decreases.

[0177] When two consecutive scans fail to detect any new confirmed defects, it is determined that no new defects can be discovered under the current signature database configuration, and the iteration process terminates. This closed-loop iteration mechanism enables the continuous accumulation and improvement of detection capabilities.

[0178] This embodiment relies on a compiler-level relational database for structure matching, enabling the identification of defect patterns across arbitrary call chains. It is not limited by single-file or single-function context windows, significantly improving the detection coverage of cross-function boundary defects. A divide-and-conquer architecture, employing exhaustive search to ensure high recall and adversarial AI semantic verification to ensure accuracy, systematically filters batches of candidate defects, effectively reducing the false positive rate to a manageable range. False reports not automatically filtered include the location information of upstream mitigation measures, facilitating manual review. A closed-loop iteration mechanism continuously improves detection capabilities with each scan round; each new defect pattern detected can be converted into a detection signature for subsequent retrieval, breaking through the limitations of traditional one-time scan methods. This method overcomes the limitations of traditional methods; it also enables efficient reuse of historical vulnerability corpora, transforming historical defect records from one-time-use data into a reusable pattern library, thus amplifying the application value of historical security corpora; during the reverse backtracking verification process of adversarial verification, it can also identify and separately mark latent defects that are masked by current operating conditions but can be activated after code modification, prompting developers to take precautions against risks during code refactoring; in addition, this method has the characteristics of universality and tool independence, with structure query signature extraction, adversarial verification, and closed-loop iteration being independent methodologies, allowing for flexible replacement of the underlying code analysis platform, and its applicability is not limited to C or C++ languages, but can be extended to various system programming languages ​​with compilation support capabilities.

[0179] The technical solution of this invention obtains the complete compilation environment and source code of the target code repository, captures the command-line parameters corresponding to each compilation unit by means of compiler tracing operations, and then combines the source code of the compilation unit with the command-line parameters to simulate the compiler front-end to complete the parsing process to obtain a structured extraction file. The structured extraction file is then imported into a relational database to construct a compilation-level relational database containing call graphs, control flow graphs, data flow graphs, and abstract syntax trees. Because it relies on the real compilation environment and the command-line parameters of the compilation unit to simulate the compiler front-end for parsing, it can restore the code organization, macro processing, and compilation branch information in the actual compilation process, avoiding the information distortion problem caused by simply parsing the source code without the compilation context. At the same time, it integrates multiple types of code graph information to form a compilation-level relational database, providing a complete and consistent code semantic foundation for subsequent structure query signature to achieve deep pattern matching across files and functions. This overcomes the limitation that single-file source code analysis cannot cover multiple call chains and ensures the integrity and authenticity of code information in the subsequent candidate defect query process.

[0180] Example 4

[0181] Figure 4 This is a schematic diagram of a code security defect detection device based on historical vulnerability corpus variant amplification, provided in Embodiment 4 of the present invention. Figure 4 As shown, the device includes:

[0182] The pattern extraction module 410 is used to obtain a historical vulnerability corpus, read the confirmed security defect records in the historical vulnerability corpus, extract the missing detection pattern that characterizes the cause of the vulnerability based on the vulnerability root cause information recorded in the security defect records, convert the missing detection pattern into a structure query signature and store it in the signature library.

[0183] The structure query module 420 is used to read the structure query signature in the signature library, perform query operations on the pre-built compiler-level relational database, and obtain a set of candidate defects.

[0184] The candidate elimination module 430 is used to eliminate dangerous operation matching items that cannot be executed synchronously under mutually exclusive branches from the candidate defect result set, eliminate false matching nodes generated by macro expansion, and obtain a candidate defect list.

[0185] The reverse backtracking module 440 is used to split the candidate defect list into multiple independent verification units according to functions and files, assign independent verification agents to each independent verification unit, and issue rebuttal instructions to each independent verification agent. Through the rebuttal instructions, each independent verification agent can backtrack from the defect danger point along the call chain to perform upstream mitigation verification and obtain structured verification results.

[0186] The result sorting module 450 is used to sort the structured verification results output by all independent verification agents according to preset types to obtain sorting results; wherein, the preset types include at least: confirming real defects;

[0187] The round iteration module 460 is used to extract common missing pattern features from the defects that confirm the true defect type in the sorting results, extract new missing detection patterns based on the common missing pattern features, convert the new missing detection patterns into new structural query signatures and write them into the signature library, and return to execute the operation of reading structural query signatures in the signature library until the number of defects that confirm the true defect type produced by the consecutive specified round iterations is zero.

[0188] The confirmation list module 470 is used to obtain the sorting result obtained from the last iteration and to construct a security defect confirmation list based on the sorting result.

[0189] The technical solution of this invention extracts missing detection patterns from security defect records based on a historical vulnerability corpus and converts them into structured query signatures stored in a signature database. It then uses a compiler-level relational database to perform signature queries to obtain a candidate defect result set. Preliminary filtering of the candidate defect result set is achieved by removing mutually exclusive branch dangerous operation matches and macro expansion false matching nodes, reducing invalid candidates and lowering the processing pressure for subsequent verification. The candidate defect list is split into independent verification units and assigned to independent verification agents. Using rebuttal instructions, these agents are driven to trace back upstream along the call chain from the defect's danger point to obtain structured verification results. This reverse falsification verification method identifies candidate defects, reducing... Reduce false alarms; sort the structured verification results according to preset types to obtain sorting results, extract common missing pattern features from the confirmed real defects in the sorting results to generate new structure query signatures to supplement the signature library, and cyclically execute the query and verification process until the iteration stop condition is met, so that the defect detection capability can be continuously expanded with iteration, fully explore the security defects of the same source variant class in the target code, and finally construct a security defect confirmation list based on the sorting results of the last iteration, outputting a well-organized defect result. This overcomes the problems of traditional detection methods, such as the inability to reuse historical vulnerability experience, failure to detect same source variant defects, insufficient authenticity of alarms, and difficulty in discovering deep defects across call chains, and improves the detection effectiveness of security defects in large code.

[0190] Based on the above embodiments, the pattern extraction module 410 is specifically used for:

[0191] Retrieve the corresponding vulnerability remediation submission record based on the associated information of the security defect record;

[0192] The newly added security guard code was located from the vulnerability patch submission records, and a missing detection pattern representing the cause of the vulnerability was extracted.

[0193] The missing detection pattern is converted into a structure query signature and stored in the signature database.

[0194] Furthermore, based on the above embodiments, the code security defect detection device based on historical vulnerability corpus variant amplification also includes:

[0195] The parameter capture module is used to obtain the complete compilation environment and source code of the target code repository before reading the structure query signature in the signature library, and capture the command line parameters corresponding to each compilation unit through compiler tracing operations;

[0196] The simulated compiler module is used to obtain the source code corresponding to each compilation unit from the source code of the target code repository, and, in combination with the corresponding command line parameters, to perform parsing processing on each compilation unit through the simulated compiler front end to obtain a structured extraction file;

[0197] The database import module is used to import all structured extraction files into a relational database to obtain a compiled-level relational database.

[0198] Among them, the compiler-level relational database includes call graphs, control flow graphs, data flow graphs, and abstract syntax trees.

[0199] Based on the above embodiments, the preset type also includes: rejected false reports; correspondingly, the defect of the rejected false report type is determined by the independent verification agent when it finds that there are security mitigation measures upstream and provides the specific documents and line numbers corresponding to the security mitigation measures.

[0200] Based on the above embodiments, the preset type further includes: defects that require hardware or runtime verification; the structured verification result includes a judgment conclusion; the judgment conclusion is a confirmed genuine defect, a rejected false report, or a defect that requires hardware or runtime verification; the structured verification result for the confirmed genuine defect type also includes a revised severity rating, triggering conditions, and exploitation scenario description; the structured verification result for the rejected false report type also includes the specific documents and line numbers of upstream security mitigation measures.

[0201] Based on the above embodiments, the vulnerability remediation submission record includes the original defective code snippet, the newly added security guard code, submission comments, and modified file path information.

[0202] Furthermore, based on the above embodiments, the code security defect detection device based on historical vulnerability corpus variant amplification also includes:

[0203] The defect marking module is used to identify and mark latent defects during the process of refuting instructions to cause each independent verification agent to trace back from the defect danger point along the call chain to perform upstream mitigation checks. Among them, latent defects are defects that are masked by the current running conditions but can be activated after subsequent code modifications.

[0204] The warning and prevention module is used to mark latent defects as risk items that will be triggered during refactoring, and to prompt risk prevention during subsequent code modification and refactoring phases.

[0205] The code security defect detection device based on historical vulnerability corpus variant amplification provided in the embodiments of the present invention can execute the code security defect detection method based on historical vulnerability corpus variant amplification provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0206] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0207] Example 5

[0208] Figure 5 A schematic diagram of an electronic device 10, which can be used to implement embodiments of the present invention, is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0209] like Figure 5 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0210] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network device, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0211] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, central processing unit (CPU), graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as code security defect detection methods based on historical vulnerability corpus variant amplification, i.e.:

[0212] Obtain the historical vulnerability corpus, read the confirmed security defect records in the historical vulnerability corpus, extract the missing detection patterns that characterize the causes of the vulnerabilities based on the vulnerability root cause information recorded in the security defect records, convert the missing detection patterns into structured query signatures and store them in the signature database.

[0213] Read the structure query signature in the signature library, perform the query operation on the pre-built compiler-level relational database, and obtain the candidate defect result set;

[0214] Remove dangerous operation matching items that cannot be executed synchronously under mutually exclusive branches from the candidate defect result set, and remove false matching nodes generated by macro expansion to obtain the candidate defect list;

[0215] The candidate defect list is split into multiple independent verification units according to functions and files. An independent verification agent is assigned to each independent verification unit, and a rebuttal instruction is issued to each independent verification agent. The rebuttal instruction enables each independent verification agent to trace back from the defect danger point along the call chain to execute the upstream mitigation verification, so as to obtain the structured verification result.

[0216] All structured verification results output by the independent verification agents are sorted according to preset types to obtain the sorting results; the preset types include at least: confirmed real defects;

[0217] Extract common missing pattern features from the defects that confirm the true defect type in the sorting results, extract new missing detection patterns based on the common missing pattern features, convert the new missing detection patterns into new structural query signatures and write them into the signature library, and return to execute the operation of reading structural query signatures in the signature library until the number of defects that confirm the true defect type produced in consecutive specified rounds of iteration is zero.

[0218] Obtain the sorting result from the last iteration, and construct a security defect confirmation list based on the sorting result.

[0219] In some embodiments, the code security flaw detection method based on historical vulnerability corpus variant amplification can be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the code security flaw detection method based on historical vulnerability corpus variant amplification described above can be performed. Alternatively, in other embodiments, processor 11 can be configured to perform the code security flaw detection method based on historical vulnerability corpus variant amplification by any other suitable means (e.g., by means of firmware).

[0220] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0221] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0222] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0223] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0224] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0225] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0226] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0227] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A code security defect detection method based on variant amplification of historical vulnerability corpora, characterized in that, include: Obtain the historical vulnerability corpus, read the confirmed security defect records in the historical vulnerability corpus, extract the missing detection patterns that characterize the causes of the vulnerabilities based on the vulnerability root cause information recorded in the security defect records, convert the missing detection patterns into structured query signatures and store them in the signature database. Read the structure query signature in the signature library, perform the query operation on the pre-built compiler-level relational database, and obtain the candidate defect result set; Remove dangerous operation matching items that cannot be executed synchronously under mutually exclusive branches from the candidate defect result set, and remove false matching nodes generated by macro expansion to obtain the candidate defect list; The candidate defect list is split into multiple independent verification units according to functions and files. An independent verification agent is assigned to each independent verification unit, and a rebuttal instruction is issued to each independent verification agent. The rebuttal instruction enables each independent verification agent to trace back from the defect danger point along the call chain to execute the upstream mitigation verification, so as to obtain the structured verification result. All structured verification results output by the independent verification agents are sorted according to preset types to obtain the sorting results; the preset types include at least: confirmed real defects; Extract common missing pattern features from the defects that confirm the true defect type in the sorting results, extract new missing detection patterns based on the common missing pattern features, convert the new missing detection patterns into new structural query signatures and write them into the signature library, and return to execute the operation of reading structural query signatures in the signature library until the number of defects that confirm the true defect type produced in consecutive specified rounds of iteration is zero. Obtain the sorting result from the last iteration, and construct a security defect confirmation list based on the sorting result.

2. The method according to claim 1, characterized in that, Based on the root cause information of vulnerabilities recorded in security defect logs, a missing detection pattern characterizing the cause of a vulnerability is extracted. This missing detection pattern is then converted into a structured query signature and stored in a signature database, including: Retrieve the corresponding vulnerability remediation submission record based on the security defect record association information; The newly added security guard code was located from the vulnerability patch submission records, and a missing detection pattern representing the cause of the vulnerability was extracted. The missing detection pattern is converted into a structure query signature and stored in the signature database.

3. The method according to claim 1, characterized in that, Before reading the structure query signature from the signature database, the process also includes: Obtain the complete compilation environment and source code of the target code repository, and capture the command-line parameters corresponding to each compilation unit through compiler tracing operations; The source code corresponding to each compilation unit is obtained from the source code of the target code repository. Combined with the corresponding command line parameters, the structured extraction file is obtained by performing parsing processing on each compilation unit through the simulated compiler front end. Import all structured extracted files into a relational database to obtain a compiled-level relational database; Among them, the compiler-level relational database includes call graphs, control flow graphs, data flow graphs, and abstract syntax trees.

4. The method according to claim 1, characterized in that, The preset types also include: rejected false reports; correspondingly, the defect of the rejected false report type is determined by the independent verification agent when it finds that there are security mitigation measures upstream and provides the specific documents and line numbers corresponding to the security mitigation measures.

5. The method according to claim 4, characterized in that, The preset types also include: defects that require hardware or runtime verification; the structured verification results include a judgment conclusion; the judgment conclusion is a confirmed genuine defect, a rejected false report, or a defect that requires hardware or runtime verification; the structured verification results for the confirmed genuine defect type also include a revised severity rating, triggering conditions, and exploitation scenario description; the structured verification results for the rejected false report type also include the specific documents and line numbers of upstream security mitigation measures.

6. The method according to claim 2, characterized in that, The vulnerability fix submission log includes the original defective code snippet, the newly added security guard code, submission comments, and modified file path information.

7. The method according to claim 1, characterized in that, The method further includes: During the process of refuting the instructions to make each independent verification agent trace back along the call chain from the defect danger point to execute the upstream mitigation verification, latent defects are identified and marked and saved; among them, latent defects are defects that are masked by the current running conditions but can be activated after subsequent code modifications; Latent defects are marked as risk items that trigger refactoring, which serves as a reminder to take precautions against risks during subsequent code modification and refactoring phases.

8. A code security defect detection device based on variant amplification of historical vulnerability corpora, characterized in that, include: The pattern extraction module is used to obtain a historical vulnerability corpus, read the confirmed security defect records in the historical vulnerability corpus, extract the missing detection patterns that characterize the causes of the vulnerabilities based on the vulnerability root cause information recorded in the security defect records, convert the missing detection patterns into structured query signatures and store them in the signature library. The structure query module is used to read the structure query signatures in the signature library, perform query operations on the pre-built compiler-level relational database, and obtain a set of candidate defects. The candidate elimination module is used to remove dangerous operation matching items that cannot be executed synchronously under mutually exclusive branches from the candidate defect result set, and to remove false matching nodes generated by macro expansion, so as to obtain a candidate defect list. The reverse backtracking module is used to split the candidate defect list into multiple independent verification units according to functions and files, assign independent verification agents to each independent verification unit, and issue rebuttal instructions to each independent verification agent. The rebuttal instructions enable each independent verification agent to backtrack from the defect danger point along the call chain to execute the upstream mitigation verification and obtain the structured verification results. The result sorting module is used to sort the structured verification results output by all independent verification agents according to preset types to obtain sorting results; wherein the preset types include at least: confirming real defects; The round iteration module is used to extract common missing pattern features from the defects that confirm the true defect type in the sorting results, extract new missing detection patterns based on the common missing pattern features, convert the new missing detection patterns into new structural query signatures and write them into the signature library, and return to execute the operation of reading structural query signatures in the signature library until the number of defects that confirm the true defect type produced by the consecutive specified round iterations is zero. The Confirmation List module is used to obtain the sorting result from the last iteration and to build a security defect confirmation list based on the sorting result.

9. An electronic device, characterized in that, The electronic device includes: At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the code security defect detection method based on historical vulnerability corpus variant amplification as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the code security defect detection method based on historical vulnerability corpus variant amplification as described in any one of claims 1-7.

11. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the code security defect detection method based on historical vulnerability corpus variant amplification as described in any one of claims 1-7.