Vulnerability type adaptive program slicing method and device, electronic equipment

By using a large language model to filter and analyze program statements in patches, the vulnerability type is automatically determined, and an adaptive slicing strategy is constructed. This solves the problem that existing technologies cannot effectively identify vulnerability-related code, achieving efficient and complete vulnerability slicing and improving the accuracy of vulnerability analysis and remediation.

CN119046947BActive Publication Date: 2025-11-11ZHEJIANG UNIV +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410956135.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-17
Publication Date
2025-11-11
Estimated Expiration
2044-07-17

Smart Images

  • Figure CN119046947B_ABST
    Figure CN119046947B_ABST
Patent Text Reader

Abstract

The application discloses a vulnerability type adaptive program slicing method and device and electronic equipment, the method filters program statements in a patch through a large language model, identifies program statements related to a vulnerability, and accurately determines a vulnerability-related slicing standard; the large language model is used to analyze the patch description and the program statements, the type of the vulnerability repaired by the patch is judged, and a suitable slicing strategy is constructed according to different vulnerability characteristics; the large language model is used to judge the integrity of the sliced code segment, so that the sliced path explosion is prevented, and the high integrity of the sliced code segment is ensured. The application can achieve the purpose of adaptively realizing high-integrity program slicing according to the type of the vulnerability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of program analysis technology, and in particular to a vulnerability type adaptive program slicing method and apparatus, and electronic equipment. Background Technology

[0002] Program slicing is a key technique in program analysis, widely used in software debugging, maintenance, and optimization. It helps developers understand and optimize code by segmenting the code and extracting parts related to specific code. Existing program slicing techniques are mainly divided into static slicing and dynamic slicing. Static slicing does not rely on the specific input of the program at runtime; it slices by analyzing the program's global data flow, control flow, and function call flow. Dynamic slicing, on the other hand, is based on a specific program execution instance, considering only the actual execution path within that instance. Although existing program slicing techniques have been widely researched and applied, modern complex software systems contain a variety of vulnerabilities, each with its own specific characteristics. However, existing program slicing techniques often fail to provide effective adaptive slicing for different types of vulnerabilities. This results in many critical code segments related to vulnerabilities not being effectively identified and segmented, thus failing to fully assist developers in a deeper understanding and analysis of related vulnerabilities, leading to the omission of many related vulnerabilities and causing serious security consequences. Summary of the Invention

[0003] To address the above shortcomings, embodiments of this application provide a vulnerability type adaptive program slicing method, apparatus, and electronic device, which can accurately and completely slice programs according to vulnerability types.

[0004] According to a first aspect of the embodiments of this application, a vulnerability type adaptive program slicing method is provided, comprising:

[0005] Collect patches, extract patch descriptions and program statements from the patches, and use patch analysis tools and vulnerability patch identification tools to filter the patches and obtain patches that fix program vulnerabilities.

[0006] The program statements in the patch that fixes the vulnerability are filtered using a large language model to obtain the program statements related to the vulnerability, which are used as the vulnerability-related slice standard.

[0007] The vulnerability type of the patch is determined by using a large language model to identify the vulnerability in the patch description and the program statements in the patch, and a preliminary slicing strategy is constructed for different vulnerability characteristics.

[0008] Based on the vulnerability-related slicing standard and the preliminary slicing strategy, the program is sliced ​​in process to obtain in-process program slices, which are considered to be the preliminary program slicing results.

[0009] The completeness of the preliminary program slicing results is determined using a large language model to obtain the preliminary slicing completeness analysis results.

[0010] Based on the preliminary slice integrity analysis results and the preliminary program slice results, a further slice strategy is constructed, and the program is further sliced ​​to obtain the final program slice results.

[0011] According to a first aspect of the embodiments of this application, a vulnerability type adaptive program slicing apparatus is provided, comprising:

[0012] The patch collection module is used to collect patches, extract patch descriptions and program statements from the patches, and use patch analysis tools and vulnerability patch identification tools to filter the patches and obtain patches that fix program vulnerabilities.

[0013] The slice standard extraction module is used to filter the program statements in the patch that fixes the vulnerability using a large language model to obtain the program statements related to the vulnerability, which are used as the vulnerability-related slice standard.

[0014] The slicing strategy construction module is used to determine the vulnerability type of the patch repair based on the patch description and the program statements in the patch using a large language model, and to construct a preliminary slicing strategy for different vulnerability characteristics.

[0015] The preliminary program slicing module is used to perform in-process slicing on the program according to the vulnerability-related slicing standard and the preliminary slicing strategy, obtain in-process program slices, and consider the in-process program slices as the preliminary program slicing results;

[0016] The integrity analysis module is used to determine the integrity of the preliminary program slicing results using a large language model, and to obtain the preliminary slicing integrity analysis results.

[0017] The further program slicing module is used to construct a further slicing strategy based on the preliminary slicing integrity analysis results and the preliminary program slicing results, and to perform further program slicing on the program to obtain the final program slicing results.

[0018] According to a third aspect of the embodiments of this application, an electronic device is provided, comprising:

[0019] One or more processors;

[0020] Memory, used to store one or more programs;

[0021] When the one or more programs are executed by the one or more processors, the one or more processors perform the method as described in the first aspect.

[0022] The technical solutions provided by the embodiments of this application may include the following beneficial effects:

[0023] As can be seen from the above embodiments, the present invention uses a large language model to filter and analyze program statements in the patch, which can accurately identify program statements directly related to the vulnerability, and thus accurately determine the vulnerability-related slice standard.

[0024] This invention automatically determines the type of vulnerability patched and constructs appropriate slicing strategies for different vulnerability characteristics, thereby achieving the effect of efficiently obtaining complete slice code related to the vulnerability by slicing according to the characteristics of different vulnerabilities.

[0025] This invention performs slicing in stages by judging the integrity of the sliced ​​code fragments, thereby preventing slice path explosion while ensuring the high integrity of the sliced ​​code fragments.

[0026] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0027] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0028] Figure 1 This is a flowchart illustrating a vulnerability type adaptive program slicing method according to an exemplary embodiment.

[0029] Figure 2 This is a block diagram illustrating a vulnerability type adaptive program slicing device according to an exemplary embodiment.

[0030] Figure 3 This is a block diagram illustrating an electronic device according to an exemplary embodiment. Detailed Implementation

[0031] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0032] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used in this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.

[0033] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."

[0034] With the rapid development of machine learning technology, it has become possible to improve the efficiency and adaptability of program slicing using large language models. A large language model is a large-scale language model built based on deep learning technology. By training on a large amount of codebase and documentation, a large language model can learn the structure, syntax, and semantic relationships of a programming language, thereby understanding the context of program code, predicting code behavior, and even inferring potential programming errors and security vulnerabilities. Therefore, large language models have great potential to play a supporting role in program slicing technology, especially in vulnerability-related program slicing analysis.

[0035] Figure 1 This is a flowchart illustrating a vulnerability type adaptive program slicing method according to an exemplary embodiment, such as... Figure 1 As shown, the method may include the following steps:

[0036] S1: Collect patches, extract patch descriptions and program statements from the patches, and use patch analysis tools and vulnerability patch identification tools to filter the patches and obtain patches that fix program vulnerabilities; this step may include the following sub-steps:

[0037] S11: Use distributed version control tools to collect patches;

[0038] Specifically, this involves using Git distributed version control tools to pull the relevant code repository from a remote code repository (such as GitHub, GitLab, etc.). The latest patches are then downloaded or updated using the `git clone` or `git pull` commands.

[0039] S12: Analyze the patch using a patch analysis tool to extract the patch description and program statements in the patch;

[0040] Specifically, first, the `git log --pretty=format:"%b"` command from the distributed version control tool is used to extract the patch description from the patch's commit history. Then, the Python PyDriller library is used to extract the program statements from the patch.

[0041] S13: The patch description and program statements in the patch are filtered using a vulnerability patch identification tool, keyword matching method and natural language processing method to obtain patches that fix vulnerabilities.

[0042] Specifically, the PatchNet vulnerability patch identification tool is used to analyze the collected patches and identify those that fix vulnerabilities. For patches that the PatchNet tool fails to identify, keyword matching and natural language processing methods are used to further identify patches related to vulnerability fixes. By combining multiple methods, the accuracy of vulnerability patch identification can be improved, and the scope of identification can be expanded to collect more vulnerability patches.

[0043] S2: Filter the program statements in the patch that fixes the vulnerability using a large language model to obtain the program statements related to the vulnerability, which will be used as the vulnerability-related slice standard; this step may include the following sub-steps:

[0044] S21: A prompting template designed for analyzing program statements related to vulnerabilities in large language models;

[0045] Specifically, based on existing teleprompter techniques, task information related to vulnerability-related program statement analysis is integrated to design a teleprompter template specifically for vulnerability-related program statement analysis using large language models. By designing a teleprompter template specifically suited for vulnerability-related program statement analysis, the potential of large language models in this task can be stimulated, providing better analysis results and ensuring the integrity and reliability of subsequent segmentation.

[0046] S22: Integrate the patch description and program statements in the patch into the prompt template, and apply the large language model to determine the vulnerability relevance of each program statement in the patch;

[0047] Specifically, the prompt template for analyzing vulnerability-related program statements in the large language model is completed using the patch description and program statements in the patch. The large language model is then called via API to obtain the vulnerability relevance judgment results of the large language model for the program statements.

[0048] S23: Based on the vulnerability correlation judgment result, filter the program statements in the patch to obtain the program statements related to the vulnerability;

[0049] Specifically, the vulnerability relevance assessment results of program statements by the large language model are processed. The natural language responses of the large language model are classified into "relevant" or "irrelevant" binary categories. Based on the classification results, each program statement is assessed line by line, and program statements with a "relevant" assessment type are considered to be vulnerability-related. By using the large language model to assess the vulnerability relevance of program statements in patches, it is helpful to accurately identify vulnerability-related program statements, laying the foundation for further accurate construction of vulnerability-related slice standards.

[0050] S24: Use a variable identification tool to extract relevant variables from the program statements related to the vulnerability, and consider the variable to be a vulnerability-related variable in the program statement.

[0051] Specifically, ClangAST is used to analyze the vulnerability-related program statements to obtain the abstract syntax graph of the program statements. Then, variables in the program statements are extracted based on the node attributes in the abstract syntax graph, and these variables are considered to be vulnerability-related variables in the program statements.

[0052] S25: Construct a tuple of <vulnerability-related variables, vulnerability-related program statements> as a vulnerability-related slice standard.

[0053] Specifically, the vulnerability-related program statements and vulnerability-related variables are saved in dictionary form as a vulnerability-related slicing standard, which facilitates reading during subsequent actual slicing.

[0054] S3: Use a large language model to determine the vulnerability type of the patch described in the patch and the program statements in the patch, and construct a preliminary slicing strategy for different vulnerability characteristics; this step may include the following sub-steps:

[0055] S31: A prompting template designed for identifying vulnerability types in large language models;

[0056] Specifically, based on existing word prompting techniques, task information for vulnerability type identification and analysis is integrated to design a word prompting template specifically for vulnerability type identification in large language models. By constructing a word prompting template specifically designed for vulnerability type identification, the potential of large language models in this task can be fully utilized, thereby providing more in-depth analysis results and ensuring the reliability and completeness of the segmentation results.

[0057] S32: Integrate the patch description, program statements in the patch, and program statements related to the vulnerability into the vulnerability type judgment prompt template, and apply the large language model to judge the vulnerability type repaired by the patch to obtain the vulnerability type repaired by the patch.

[0058] Specifically, the prompt template for vulnerability type judgment using the large language model is completed by supplementing the patch description and program statements in the patch with vulnerability-related program statements. The large language model is then called via API to obtain its analysis results for vulnerability type judgment. Through further processing of the natural language response from the large language model, the judgment is categorized into common vulnerability types.

[0059] S33: Utilize a large language model to further analyze the patch description, vulnerability-related program statements, and vulnerability types patched by the patch, and construct a slicing strategy; this step may include the following sub-steps:

[0060] S331: A word-prompting template designed for slicing strategies in large language model construction;

[0061] Specifically, based on existing word extraction techniques, task information for constructing slicing strategies is integrated, and a word extraction template specifically designed for constructing slicing strategies in large language models is developed. By designing a word extraction template specifically for constructing slicing strategies, large language models can better complete the task of constructing slicing strategies, thereby ensuring the reliability and completeness of subsequent slicing results.

[0062] S332: Integrate the patch description, vulnerability-related program statements, and vulnerability types repaired by the patch into the prompting template for the construction of the slicing strategy, and apply a large language model to perform slicing strategy analysis.

[0063] Specifically, the word prompt template for the slicing strategy constructed using the large language model is supplemented with patch descriptions, vulnerability-related program statements, and vulnerability types patched by the patch. The large language model is then called via API to obtain its analysis results for the slicing strategy. By utilizing the large language model to construct slicing strategies based on vulnerability types and characteristics, the adaptability of the sliced ​​code to vulnerabilities is effectively guaranteed, ensuring the integrity of vulnerability-related code within the slices.

[0064] S333: Extract the analysis results of the slicing strategy and construct a triplet of <slicing direction, code representation graph type, slice depth> as the constructed slicing strategy.

[0065] Specifically, by analyzing the natural language response format of the large language model, the analysis results of the large language model for slice direction, code representation graph type, and slice depth are extracted. Based on the results, a triple <slice direction, code representation graph type, slice depth> is constructed and saved in dictionary format for subsequent actual slice execution.

[0066] S4: Based on the vulnerability-related slicing standards and the preliminary slicing strategy, perform in-process slicing on the program to obtain in-process program slices, and consider the in-process program slices as the preliminary program slicing results; this step may include the following sub-steps:

[0067] S41: Based on the code representation graph type and slice depth in the <slice direction, code representation graph type, slice depth> triplet of the initial slicing strategy, generate a code representation graph of the corresponding type under the program slice depth setting.

[0068] Specifically, based on the slicing direction of the initial slicing strategy, the slicing orientation is determined to be forward slicing, backward slicing, or bidirectional slicing; based on the code representation graph type, the code representation graph on which the slicing is based is determined to be control flow graph, data flow graph, program dependency graph, code dependency graph, or function call graph; based on the slice depth, the number of nodes limited by the slice depth is determined. Subsequently, the Joern code analysis tool is used to generate the corresponding code representation graph according to the above settings. By generating the code representation graph according to the slice depth set by the slicing strategy, path explosion can be prevented, effectively improving the efficiency of code representation graph generation.

[0069] S42: Extract the vulnerability-related variables and vulnerability-related program statements from the standard binary tuple <vulnerability-related variables, vulnerability-related program statements> of the vulnerability-related slice, and locate the corresponding nodes of the vulnerability-related variables and vulnerability-related program statements in the code representation diagram;

[0070] Specifically, the generated code representation graph is read, and nodes in the same position in the code representation graph are matched according to the position of the vulnerability-related program statements in the file. The nodes that match successfully are considered to be the corresponding nodes of the vulnerability-related variables and vulnerability-related program statements in the code representation graph.

[0071] S43: Based on the vulnerability-related variables and vulnerability-related program statements in the corresponding nodes of the code representation graph, the slicing direction of the preliminary slicing strategy, and the directed relationships between nodes in the code representation graph, obtain the slicing-related nodes;

[0072] Specifically, the generated code representation graph is read, and the edges and their associated nodes are extracted and represented as <previous node, next node, edge type> edge relationship triples. Starting from the corresponding nodes of the vulnerability-related variables and program statements in the code representation graph, nodes are acquired along the edges of the code representation graph according to the slicing direction and the obtained edge relationship triples. The acquired nodes are considered to be slice-related nodes. By slicing according to an adaptive slicing direction, the code most relevant to the vulnerability can be effectively found according to different vulnerability types, ensuring the reliability and effectiveness of the slicing results.

[0073] S44: Extract the program statements in the program that correspond to the nodes related to the slice, and consider all the extracted program statements to constitute the preliminary program slicing result.

[0074] Specifically, the slice-related nodes and program files are read, the code lines where the slice-related nodes are located are extracted, the corresponding program statements of the slice-related nodes in the program file are extracted based on the code line information, and all the extracted program statements are arranged according to the line number of the code line in the program file to form a preliminary program slicing result.

[0075] S5: Use a large language model to determine the completeness of the preliminary program slicing results and obtain the preliminary slicing completeness analysis results;

[0076] Specifically, a prompting template was designed specifically for large language models to determine the integrity of code related to vulnerabilities. The program slicing results were integrated into the prompting template, and an API was used to call the large language model to obtain its integrity analysis of the program slices. By performing integrity analysis on program slices using the large language model, the slicing process can be segmented to prevent path explosion during inter-process slicing due to excessive code volume. Furthermore, it can effectively determine whether existing slicing results are complete, thereby deciding whether further slicing is necessary and ensuring the integrity of the program slices.

[0077] S6: Based on the preliminary slice integrity analysis results and the preliminary program slice results, construct a further slice strategy and perform further program slices to obtain the final program slice results. This step may include the following sub-steps:

[0078] S61: If the preliminary slice integrity analysis result is that the program slice is complete, then the preliminary program slice result is considered to be the final program slice result, and the program slicing ends;

[0079] Specifically, based on the integrity analysis of the preliminary slicing results, if the integrity analysis result indicates that the program slice is complete, no further slicing operations will be performed, and this result will be used as the final program slicing result, ensuring the efficiency and accuracy of the slicing process.

[0080] S62: If the preliminary slice integrity analysis result is that the program slice is incomplete, then the preliminary program slice result is further analyzed through the large language model to construct an inter-process slicing strategy, which is considered to be the further program slicing strategy;

[0081] Specifically, the word-prompting template for the large language model's slicing strategy is completed using preliminary program slicing results and patched vulnerability types. The large language model is then accessed via API calls to obtain its analysis results for further program slicing strategies. Subsequently, the natural language response format of the large language model is analyzed to extract its analysis results for slice direction, code representation graph type, and slice depth. Based on these results, a triple of <slice direction, code representation graph type, slice depth> is constructed and saved in dictionary format. This process ensures the comprehensiveness and accuracy of program slicing, providing a reliable foundation for developers to analyze and fix vulnerabilities.

[0082] S63: Based on the preliminary program slicing results and the further program slicing strategy, perform further program slicing on the program to obtain further program slicing results; this step may include the following sub-steps:

[0083] S631: Based on the code representation graph type and slice depth in the <slice direction, code representation graph type, slice depth> triple of the further program slicing strategy, generate a code representation graph of the corresponding type under the program slice depth setting.

[0084] Specifically, based on the slicing direction of the further program slicing strategy, the slice orientation is determined to be forward slicing, backward slicing, or bidirectional slicing; based on the code representation graph type, the code representation graph on which the slicing is based is determined to be control flow graph, data flow graph, program dependency graph, code dependency graph, or function call graph; based on the slice depth, the slice range limited by the slice depth is determined to be intra-file slicing or cross-file slicing. Then, the Joern code analysis tool is used to generate the corresponding code representation graph according to the above settings. By generating the code representation graph according to the slice depth set by the slicing strategy, path explosion can be prevented, effectively improving the efficiency of code representation graph generation.

[0085] S632: Based on the program statements and variables in the preliminary program slicing results, construct a tuple <variables in program statements, program statements in the preliminary program slicing results> as the slicing standard;

[0086] Specifically, each program statement in the preliminary program slicing result is extracted, and each extracted program statement is analyzed using ClangAST to obtain an abstract syntax graph of the program statement. Then, variables in the program statement are extracted based on the node attributes in the abstract syntax graph. The extracted variables are considered to be variables in the program statements in the preliminary program slicing result, and the extracted program statements are considered to be program statements in the preliminary program slicing result. A tuple <variables in program statements, program statements in the preliminary program slicing result> is constructed and saved as the slicing standard for further program slicing.

[0087] S633: Based on the slicing criteria, locate the corresponding nodes of the program statements and variables in the program statements in the code representation diagram in the preliminary program slicing result;

[0088] Specifically, the generated code representation graph is read, and nodes in the same position in the code representation graph are matched according to the position of the program statements in the file in the preliminary program slicing results. The nodes that are successfully matched are considered to be the variables in the program statements and the corresponding nodes of the program statements in the preliminary program slicing results in the code representation graph.

[0089] S634: Based on the corresponding nodes in the code representation graph, the slicing direction of the further program slicing strategy, and the directed relationships between nodes in the code representation graph, obtain the slicing-related nodes;

[0090] Specifically, the generated code representation graph is read, and the edges and related nodes in the code representation graph are extracted and represented as <previous node, next node, edge type> edge relationship triples. Starting from the corresponding nodes of the variables in the program statements and the program statements in the preliminary program slicing results in the code representation graph, nodes are obtained along the edges of the code representation graph according to the slicing direction and the obtained edge relationship triples. The obtained nodes are considered to be slice-related nodes.

[0091] S635: Extract program statements from the program that correspond to the nodes related to the slice, and consider all extracted program statements to constitute the result of further program slicing;

[0092] Specifically, the slice-related nodes and program files are read, the code lines where the slice-related nodes are located are extracted, the corresponding program statements of the slice-related nodes in the program file are extracted based on the code line information, and all the extracted program statements are arranged according to the line number of the code line in the program file to form a further program slicing result.

[0093] S64: Use a large language model to determine the completeness of the further program slicing results and obtain the completeness analysis results of the further slicing.

[0094] Specifically, the results of further program slicing are integrated into a prompting template specifically used for large language model judgment and vulnerability-related code integrity. The large language model is then called using an API to obtain the integrity analysis of the large language model for further program slicing, thus obtaining the results of the further slicing integrity analysis.

[0095] S65: If the result of the further slice integrity analysis is that the program slice is complete, then the result of the further program slice is considered to be the final program slice result, and the program slice is terminated;

[0096] Specifically, a completeness analysis is performed on the further program slicing results using a large language model to confirm that the slicing results cover all necessary code paths and logic, and that there are no missing parts. If the analysis results indicate that the program slice is complete, this further program slicing result is considered the final result, and the program slicing process ends, ensuring the efficiency and accuracy of the final slicing result.

[0097] S66: If the result of the further slice integrity analysis is that the program slice is incomplete, then the result of the further program slice is considered to be the preliminary program slice result, and this step is continued until the result of the further slice integrity analysis is that the program slice is complete;

[0098] Specifically, based on the results of further slice integrity analysis, the slicing strategy is readjusted and optimized by identifying missing parts and problem areas through the large language model. The current further program slicing result is used as the new preliminary program slicing result, and all sub-steps in step S6 are repeated to continue slicing and integrity analysis. This process iterates until the large language model confirms the program slicing result is complete, covering all necessary code paths and logic, ultimately obtaining a complete program slicing result. By judging the integrity of the sliced ​​code fragments in stages and performing slicing operations step by step, both slice path explosion and high integrity of the sliced ​​code fragments are effectively prevented.

[0099] As can be seen from the above embodiments, this application, by utilizing a large language model to filter and analyze program statements in patches, can accurately identify program statements directly related to vulnerabilities, thereby precisely determining vulnerability-related segmentation standards. By automatically determining the type of vulnerability patched and constructing appropriate segmentation strategies for different vulnerability characteristics, it achieves the effect of efficiently obtaining complete vulnerability-related segmented code by slicing according to the characteristics of different vulnerabilities. By judging the integrity of segmented code fragments and performing segmentation in stages, it prevents segmentation path explosion while ensuring high integrity of segmented code fragments.

[0100] Corresponding to the aforementioned embodiments of the vulnerability type adaptive program slicing method, this application also provides embodiments of the vulnerability type adaptive program slicing apparatus.

[0101] Figure 2 This is a block diagram illustrating a vulnerability type adaptive program slicing device according to an exemplary embodiment. (Refer to...) Figure 2 The device includes:

[0102] The patch collection module 1 is used to collect patches, extract patch descriptions and program statements from the patches, and use patch analysis tools and vulnerability patch identification tools to filter the patches and obtain patches that fix program vulnerabilities.

[0103] The slice standard extraction module 2 is used to filter the program statements in the patch that fixes the vulnerability using a large language model to obtain the program statements related to the vulnerability, which are used as the vulnerability-related slice standard.

[0104] The slicing strategy construction module 3 is used to determine the vulnerability type of the patch repair based on the patch description and the program statements in the patch using a large language model, and to construct a preliminary slicing strategy for different vulnerability characteristics.

[0105] The preliminary program slicing module 4 is used to perform in-process slicing on the program according to the vulnerability-related slicing standard and the preliminary slicing strategy, obtain in-process program slices, and consider the in-process program slices as the preliminary program slicing results;

[0106] Integrity analysis module 5 is used to judge the integrity of the preliminary program slicing results using a large language model to obtain the preliminary slicing integrity analysis results;

[0107] The further program slicing module 6 is used to construct a further slicing strategy based on the preliminary slicing integrity analysis results and the preliminary program slicing results, and to perform further program slicing on the program to obtain the final program slicing results.

[0108] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.

[0109] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this application according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0110] Accordingly, this application also provides an electronic device, including: one or more processors; a memory for storing one or more programs; and when the one or more programs are executed by the one or more processors, causing the one or more processors to implement the vulnerability type adaptive program slicing method as described above. Figure 3 The diagram shown is a hardware structure diagram of any data processing-capable device where a vulnerability type adaptive program slicing device provided in an embodiment of the present invention is located, except... Figure 3In addition to the processor, memory, DMA controller, disk, and non-volatile memory shown, any data processing device in the embodiment may also include other hardware depending on the actual function of the data processing device, which will not be described in detail here.

[0111] Accordingly, this application also provides a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the vulnerability type adaptive program slicing method described above. The computer-readable storage medium can be an internal storage unit of any data-processing device as described in any of the foregoing embodiments, such as a hard disk or memory. The computer-readable storage medium can also be an external storage device, such as a plug-in hard disk, smart media card (SMC), SD card, flash card, etc., equipped on the device. Furthermore, the computer-readable storage medium can include both internal storage units of any data-processing device and external storage devices. The computer-readable storage medium is used to store the computer program and other programs and data required by the data-processing device, and can also be used to temporarily store data that has been output or will be output.

[0112] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the disclosure herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and embodiments are to be considered exemplary only, and the true scope and spirit of this application are indicated by the claims.

[0113] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A vulnerability type-adaptive program slicing method, characterized in that, include: Collect patches, extract patch descriptions and program statements from the patches, and use patch analysis tools and vulnerability patch identification tools to filter the patches and obtain patches that fix program vulnerabilities. The program statements in the patch that fixes the vulnerability are filtered using a large language model to obtain the program statements related to the vulnerability, which are used as the vulnerability-related slice standard. The vulnerability type of the patch is determined by using a large language model to identify the vulnerability in the patch description and the program statements in the patch, and a preliminary slicing strategy is constructed for different vulnerability characteristics. Based on the vulnerability-related slicing standard and the preliminary slicing strategy, the program is sliced ​​in process to obtain in-process program slices, which are considered to be the preliminary program slicing results. The completeness of the preliminary program slicing results is determined using a large language model to obtain the preliminary slicing completeness analysis results. Based on the preliminary slice integrity analysis results and the preliminary program slice results, a further slice strategy is constructed, and the program is further sliced ​​to obtain the final program slice results.

2. The method according to claim 1, characterized in that, Collect patches, extract patch descriptions and program statements from the patches, and use patch analysis tools and vulnerability patch identification tools to filter the patches and obtain patches that fix program vulnerabilities, including: Use distributed version control tools to collect patches; The patch is analyzed using a patch analysis tool to extract the patch description and program statements within the patch. The patch description and program statements in the patch are filtered using vulnerability patch identification tools, keyword matching methods, and natural language processing methods to obtain patches that fix vulnerabilities.

3. The method according to claim 1, characterized in that, The program statements in the patch are filtered using a large language model to obtain program statements related to the vulnerability, which are used as vulnerability-related slice criteria, including: Design a prompting template for analyzing program statements related to vulnerabilities in large language models; The patch description and program statements in the patch are integrated into the prompt template, and the vulnerability relevance of each program statement in the patch is determined by a large language model. Based on the vulnerability correlation judgment results, the program statements in the patch are filtered to obtain the program statements related to the vulnerability; Using a variable identification tool, relevant variables are extracted from the program statements related to the vulnerability, and these variables are considered to be vulnerability-related variables in the program statements. Construct a tuple of <vulnerability-related variables, vulnerability-related program statements> as a vulnerability-related slice standard.

4. The method according to claim 1, characterized in that, The vulnerability type of the patch is determined using a large language model based on the patch description and the program statements within the patch. A preliminary slicing strategy is then constructed for different vulnerability characteristics, including: Design a prompting template for identifying vulnerability types in large language models; The patch description, program statements in the patch, and program statements related to the vulnerability are integrated into the vulnerability type judgment prompt template. A large language model is applied to judge the vulnerability type repaired by the patch to obtain the vulnerability type repaired by the patch. The patch description, vulnerability-related program statements, and vulnerability types repaired by the patch are further analyzed using a large language model to construct a slicing strategy.

5. The method according to claim 4, characterized in that, Further analysis of the patch description, vulnerability-related program statements, and vulnerability types patched by the patch is conducted using a large language model to construct a slicing strategy, including: Design a word-prompting template for slicing strategies in large language model construction; The patch description, vulnerability-related program statements, and vulnerability types repaired by the patch are integrated into the prompting template for the construction slicing strategy, and a large language model is applied to perform slicing strategy analysis. The analysis results of the slicing strategy are extracted, and a triple of <slicing direction, code representation graph type, slice depth> is constructed as the slicing strategy.

6. The method according to claim 1, characterized in that, Based on the vulnerability-related slicing standards and the preliminary slicing strategy, the program is sliced ​​in-process to obtain in-process program slices, which are considered to be the preliminary program slicing results, including: Based on the code representation graph type and slice depth in the <slice direction, code representation graph type, slice depth> triplet of the initial slicing strategy, generate a code representation graph of the corresponding type under the program slice depth setting; Extract the vulnerability-related variables and vulnerability-related program statements from the standard binary tuple <vulnerability-related variables, vulnerability-related program statements> of the vulnerability-related slice, and locate the corresponding nodes of the vulnerability-related variables and vulnerability-related program statements in the code representation graph; Based on the corresponding nodes of the vulnerability-related variables and vulnerability-related program statements in the code representation graph, the slicing direction of the preliminary slicing strategy, and the directed relationships between nodes in the code representation graph, obtain the slicing-related nodes; Extract the program statements that correspond to the nodes related to the slice in the program, and consider all the extracted program statements to constitute the preliminary program slicing result.

7. The method according to claim 1, characterized in that, Based on the preliminary slice integrity analysis results and the preliminary program slice results, a further slice strategy is constructed, and the program is further sliced ​​to obtain the final program slice results, including: If the preliminary slice integrity analysis result indicates that the program slice is complete, then the preliminary program slice result is considered to be the final program slice result, and the program slicing ends. If the preliminary slice integrity analysis result is that the program slice is incomplete, then the preliminary program slice result is further analyzed through the large language model to construct an inter-process slicing strategy, which is considered to be the further slicing strategy. Based on the preliminary program slicing results and the further slicing strategy, the program is further sliced ​​to obtain further program slicing results. The completeness of the further program slicing results is judged using a large language model to obtain the completeness analysis results of the further slicing. If the result of the further slice integrity analysis is that the program slice is complete, then the further program slice result is considered to be the final program slice result, and the program slicing ends; If the result of the further slice integrity analysis is that the program slice is incomplete, then the result of the further program slice is considered to be the preliminary program slice result, and this step is continued until the result of the further slice integrity analysis is that the program slice is complete.

8. The method according to claim 7, characterized in that, Based on the preliminary program slicing results and the further slicing strategy, the program is sliced ​​to obtain further program slicing results, including: Based on the code representation graph type and slice depth in the <slice direction, code representation graph type, slice depth> triplet of the further slicing strategy, generate a code representation graph of the corresponding type under the program slice depth setting; Based on the program statements and variables in the preliminary program slicing results, construct a tuple <variables in program statements, program statements in the preliminary program slicing results> as the slicing standard; Based on the slicing criteria, locate the corresponding nodes of the program statements and variables in the program statements in the code representation diagram in the preliminary program slicing results; Based on the corresponding nodes in the code representation graph, the slicing direction of the further slicing strategy, and the directed relationships between nodes in the code representation graph, obtain the slicing-related nodes; Extract the program statements that correspond to the nodes related to the slice in the program, and consider all the extracted program statements to constitute the result of further program slicing.

9. A vulnerability type-adaptive program slicing device, characterized in that, include: The patch collection module is used to collect patches, extract patch descriptions and program statements from the patches, and use patch analysis tools and vulnerability patch identification tools to filter the patches and obtain patches that fix program vulnerabilities. The slice standard extraction module is used to filter the program statements in the patch that fixes the vulnerability using a large language model to obtain the program statements related to the vulnerability, which are used as the vulnerability-related slice standard. The slicing strategy construction module is used to determine the vulnerability type of the patch repair based on the patch description and the program statements in the patch using a large language model, and to construct a preliminary slicing strategy for different vulnerability characteristics. The preliminary program slicing module is used to perform in-process slicing on the program according to the vulnerability-related slicing standard and the preliminary slicing strategy, obtain in-process program slices, and consider the in-process program slices as the preliminary program slicing results; The integrity analysis module is used to determine the integrity of the preliminary program slicing results using a large language model, and to obtain the preliminary slicing integrity analysis results. The further program slicing module is used to construct a further slicing strategy based on the preliminary slicing integrity analysis results and the preliminary program slicing results, and to perform further program slicing on the program to obtain the final program slicing results.

10. An electronic device, characterized in that, include: One or more processors; Memory, used to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Code defect analysis method and device

    CN117171741A

  • System and method for auto repairing vulnerable code program fragments of a software

    EP4386601A1