Vulnerability type adaptive program slicing method and device and electronic equipment
Through a large language model, filter and analyze program statements in the patch, automatically judge vulnerability types and build slicing strategies, solving the problem of slicing that cannot be effectively adapted to different vulnerability types in the existing technology, and accurately identify and slice vulnerabilities, preventing them from being able to prevent them. Vulnerability omissions and security consequences.
Patent Information
- Application Number
- CN202410956135.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-17
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2044-07-17
AI Technical Summary
The existing program slicing technology cannot effectively slice adaptively for different types of vulnerabilities, resulting in the vulnerability-related key code snippets that cannot be fully identified and segmented, which will lead to the vulnerability and security consequences of the vulnerability.
A large language model is used to filter and analyze program statements in the patch, automatically judge vulnerability types, and build slicing strategies based on different vulnerability characteristics, and slicing is achieved through staged slicing to ensure the integrity and efficiency of the slice code.
Accurate identification and slicing of vulnerabilities is achieved, preventing the slicing path from exploding, and ensuring high integrity and security of the slicing code.
Smart Images

Figure CN119046947A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of program analysis technology, and in particular to a vulnerability type adaptive program slicing method and device, and electronic equipment. Background Art
[0002] Program slicing technology is a key technology in program analysis and is widely used in software debugging, maintenance, optimization and other fields. It helps developers understand and optimize the code by segmenting the program code and extracting the program parts related to specific codes. Existing program slicing technologies are mainly divided into two categories: static slicing technology and dynamic slicing technology. Among them, static program slicing does not rely on the specific input of the program at runtime. It slices by analyzing the global data flow, control flow, function call flow and other information of the program, while dynamic program slicing is based on a specific program execution instance and only considers the actual execution path in the instance for slicing. Although the existing program slicing technology has been widely studied and applied, in modern complex software systems, there are many types of vulnerabilities, and each vulnerability has its own specific characteristics. However, the existing program slicing technology often cannot perform effective adaptive slicing for different types of vulnerabilities. This results in many key code fragments related to vulnerabilities cannot be effectively identified and segmented, which cannot fully assist developers in their in-depth understanding and analysis of related vulnerabilities, which in turn leads to the omission of many related vulnerabilities, resulting in serious security consequences. Summary of the invention
[0003] In order to solve the above shortcomings, the embodiments of the present application provide a vulnerability type adaptive program slicing method and device, and an electronic device, which can accurately and completely perform vulnerability type adaptive program slicing on a program.
[0004] According to a first aspect of an embodiment of the present application, a vulnerability type adaptive program slicing method is provided, including:
[0005] Collect patches, extract patch descriptions and program statements in the patches, and use patch analysis tools and vulnerability repair patch identification tools to screen the patches to obtain patches that repair program vulnerabilities;
[0006] Using a large language model to screen program statements in the patch for fixing the program vulnerability, and obtaining program statements related to the vulnerability as vulnerability-related slicing standards;
[0007] Using a large language model to determine the vulnerability type to be repaired by the patch description and program statements in the patch, and constructing a preliminary slicing strategy for different vulnerability features;
[0008] According to the vulnerability-related slicing standard and the preliminary slicing strategy, the program is sliced in-process to obtain the in-process program slice, and the in-process program slice is considered to be the preliminary program slicing result;
[0009] Using a large language model to determine the integrity of the preliminary program slicing result, to obtain a preliminary slicing integrity analysis result;
[0010] Based on the preliminary slicing integrity analysis result and the preliminary program slicing result, a further slicing strategy is constructed, and the program is further sliced to obtain a final program slicing result.
[0011] According to a first aspect of an embodiment of the present application, a vulnerability type adaptive program slicing device is provided, including:
[0012] A patch collection module is used to collect patches, extract patch descriptions and program statements in the patches, and use patch analysis tools and vulnerability repair patch identification tools to screen the patches to obtain patches that repair program vulnerabilities;
[0013] A slicing standard extraction module is used to screen the program statements in the patch for fixing the program vulnerability using a large language model, and obtain program statements related to the vulnerability as vulnerability-related slicing standards;
[0014] A slicing strategy building module is used to use a large language model to determine the vulnerability type of the patch repair based on the patch description and the program statements in the patch, and to build a preliminary slicing strategy for different vulnerability features;
[0015] A preliminary program slicing module, used to perform intra-process slicing on the program according to the vulnerability-related slicing standard and the preliminary slicing strategy, obtain intra-process program slices, and consider the intra-process program slices as preliminary program slicing results;
[0016] An integrity analysis module, used to determine the integrity of the preliminary program slicing result using a large language model to obtain a preliminary slicing integrity analysis result;
[0017] The further program slicing module is used to construct a further slicing strategy based on the preliminary slicing integrity analysis result and the preliminary program slicing result, and to perform further program slicing on the program to obtain a final program slicing result.
[0018] According to a third aspect of an embodiment of the present application, there is provided an electronic device, including:
[0019] one or more processors;
[0020] A memory for storing one or more programs;
[0021] 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 the first aspect.
[0022] The technical solution provided by the embodiments of the present application may have the following beneficial effects:
[0023] It can be seen from the above embodiments that the present invention uses a large language model to screen and analyze program statements in a patch, which can accurately identify program statements directly related to the vulnerability, and then accurately determine the vulnerability-related slicing standards.
[0024] The present invention automatically determines the type of vulnerability repaired by the patch, and constructs a suitable slicing strategy according to different vulnerability characteristics, thereby slicing according to the characteristics of different vulnerabilities and realizing the effect of efficiently obtaining the complete slicing code related to the vulnerability.
[0025] The present invention determines the integrity of the slice code fragments and performs slicing in stages, thereby preventing the slice path from exploding and ensuring the high integrity of the slice code fragments.
[0026] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0028] Figure 1 It is a flowchart of a vulnerability type adaptive program slicing method according to an exemplary embodiment.
[0029] Figure 2 It is a block diagram of a vulnerability type adaptive program slicing device according to an exemplary embodiment.
[0030] Figure 3 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0031] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0032] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0033] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0034] With the rapid development of machine learning technology, it is possible to use large language models to improve the efficiency and adaptability of program slicing. A large language model is a large-scale language model built based on deep learning technology. By training a large number of code bases and document materials, the large language model can learn the structure, syntax and semantic associations of programming languages, and then understand the context of program code, predict code behavior, and even infer potential programming errors and security vulnerabilities. Therefore, large language models have great potential to play an auxiliary role in program slicing technology, especially in program slicing analysis related to vulnerabilities.
[0035] Figure 1 is a flowchart of a vulnerability type adaptive program slicing method according to an exemplary embodiment. Figure 1 As shown, the method may include the following steps:
[0036] S1: Collect patches, extract patch descriptions and program statements in the patches, and use patch analysis tools and vulnerability repair patch identification tools to screen the patches to obtain patches that repair program vulnerabilities; this step may include the following sub-steps:
[0037] S11: Collect patches using distributed version control tools;
[0038] Specifically, by using the Git distributed version control tool, pull the relevant code base from the remote code repository (such as GitHub, GitLab, etc.). Use the git clone or git pull command to download or update the latest patch.
[0039] S12: Analyze the patch using a patch analysis tool to extract a patch description of the patch and program statements in the patch;
[0040] Specifically, the git log --pretty=format:"%b" command of the distributed version control tool is first used to extract the patch description part of the patch from the patch submission history. Thereafter, the Python PyDriller library is used to extract the program statements in the patch.
[0041] S13: Applying a vulnerability repair patch identification tool, a keyword matching method and a natural language processing method to the patch description and program statements in the patch to screen the patch and obtain a patch that repairs the vulnerability.
[0042] Specifically, the PatchNet vulnerability patch identification tool is used to analyze the collected patches and identify patches that fix vulnerabilities. For patches that the PatchNet vulnerability patch identification tool fails to identify, keyword matching and natural language processing methods are used to further identify patches related to vulnerability repairs. By combining multiple methods, on the one hand, the accuracy of identifying patches that fix vulnerabilities can be improved, and on the other hand, the identification scope can be expanded to collect more patches that fix vulnerabilities.
[0043] S2: Screening the program statements in the patch for fixing the program vulnerability using a large language model to obtain program statements related to the vulnerability as vulnerability-related slicing standards; this step may include the following sub-steps:
[0044] S21: Design a prompt template for analyzing program statements related to large language model vulnerabilities;
[0045] Specifically, based on the existing prompting technology, we integrated the task information of vulnerability-related program statement analysis and designed a prompting template specifically for vulnerability-related program statement analysis in a large language model. By designing a prompting template specifically suitable for vulnerability-related program statement analysis, we can stimulate the potential of the large language model in this task, provide better analysis results, and ensure the integrity and reliability of subsequent slices.
[0046] S22: Integrate the patch description for fixing the program vulnerability and the program statements in the patch into a prompting template, and use a large language model to perform vulnerability relevance judgment on the program statements in the patch sentence by sentence;
[0047] Specifically, the prompt template for analyzing the program statements related to the large language model vulnerabilities is completed using the patch description of the patch and the program statements in the patch, and the large language model is called through the API to obtain the vulnerability relevance judgment result of the large language model for the program statements.
[0048] S23: Screening program statements in the patch according to the vulnerability correlation judgment result to obtain program statements related to the vulnerability;
[0049] Specifically, the large language model is used to process the vulnerability relevance judgment results of program statements, and the natural language responses of the large language model are binary classified as "relevant" or "irrelevant". Based on the above classification results, each program statement is judged sentence by sentence, and program statements with a judgment type of "relevant" are considered to be program statements related to the vulnerability. By using the large language model to judge the vulnerability relevance of program statements in the patch, it is helpful to accurately identify program statements related to the vulnerability, laying the foundation for further accurately constructing slicing standards related to the vulnerability.
[0050] S24: applying a variable identification tool to extract relevant variables in the program statement related to the vulnerability, and considering the variable as a vulnerability-related variable in the program statement.
[0051] Specifically, ClangAST is used to analyze the program statements related to the vulnerability, obtain the abstract syntax graph of the program statements, and then extract the variables in the program statements according to the node attributes in the abstract syntax graph, and the variables are considered to be the vulnerability-related variables in the program statements.
[0052] S25: Construct a <vulnerability-related variable, vulnerability-related program statement> tuple as a vulnerability-related slicing standard.
[0053] Specifically, the program statements related to the vulnerability and the vulnerability related variables are saved in the form of a dictionary as a vulnerability related slicing standard, so as to facilitate reading during subsequent actual slicing.
[0054] S3: Using a large language model to determine the vulnerability type to be repaired by the patch description and the program statements in the patch, and constructing a preliminary slicing strategy for different vulnerability features; this step may include the following sub-steps:
[0055] S31: Design a prompt template for large language model vulnerability type judgment;
[0056] Specifically, based on the existing word prompting technology, we integrated the task information of vulnerability type judgment and analysis, and designed a word prompting template specifically for large language model vulnerability type judgment. By building a word prompting template designed specifically for vulnerability type identification, we can fully stimulate the potential of large language models in this task, thereby providing more in-depth analysis results and ensuring the reliability and completeness of slicing results.
[0057] S32: Integrate the patch description of the patch, the program statements in the patch, and the program statements related to the vulnerability into the vulnerability type judgment prompt template, apply the large language model to judge the vulnerability type repaired by the patch, and obtain the vulnerability type repaired by the patch;
[0058] Specifically, the prompt template for the vulnerability type judgment of the large language model is supplemented with the patch description of the patch and the program statements in the patch with the program statements related to the vulnerability, and the large language model is called through the API to obtain the analysis results of the large language model for the vulnerability type judgment. Through further processing of the natural language response of the large language model, the judgment of the large language model is classified into common vulnerability types.
[0059] S33: Using a large language model, further analyze the patch description of the patch, the program statements related to the vulnerability, and the vulnerability type fixed by the patch to construct a slicing strategy; this step may include the following sub-steps:
[0060] S331: Designing prompt templates for building slicing strategies for large language models;
[0061] Specifically, based on the existing word prompting technology, the task information of constructing the slicing strategy is integrated, and a word prompting template dedicated to constructing the slicing strategy for the large language model is designed. By designing a word prompting template specifically for constructing the slicing strategy, the large language model can be helped to better complete the slicing strategy construction task, thereby ensuring the reliability and completeness of the subsequent slicing results.
[0062] S332: Integrate the patch description of the patch, the program statements related to the vulnerability, and the vulnerability type fixed by the patch into the prompting template for constructing the slicing strategy, and apply the large language model to perform slicing strategy analysis;
[0063] Specifically, the prompt template for constructing the slicing strategy with the large language model is supplemented with the patch description of the patch, the program statements related to the vulnerability, and the type of vulnerability fixed by the patch. The large language model is called through the API to obtain the analysis results of the large language model for the slicing strategy. By using the large language model to build a slicing strategy based on the vulnerability type and vulnerability characteristics, the adaptability of the slicing code to the vulnerability is effectively guaranteed, ensuring the integrity of the vulnerability-related code in the slice.
[0064] S333: Extract the slicing strategy analysis result and construct a <slicing direction, code representation graph type, slicing depth> triple 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 slicing direction, code representation graph type, and slicing depth are extracted, and a triple of <slicing direction, code representation graph type, slicing depth> is constructed based on the results and saved in a dictionary format for subsequent actual slicing execution.
[0066] S4: Slice the program in-process according to the vulnerability-related slicing standard and the preliminary slicing strategy to obtain in-process program slices, and consider the in-process program slices as preliminary program slicing results; this step may include the following sub-steps:
[0067] S41: Generate a code representation graph of a corresponding type under the program slicing depth setting according to the code representation graph type and slicing depth in the <slicing direction, code representation graph type, slicing depth> triplet of the preliminary slicing strategy.
[0068] Specifically, according to the slicing direction of the preliminary slicing strategy, determine whether the slicing orientation is forward slicing, backward slicing or bidirectional slicing; according to the code representation graph type, determine whether the code representation graph based on slicing is a control flow graph, a data flow graph, a program dependency graph, a code dependency graph or a function call graph; according to the slicing depth, determine the number of nodes limited by the slicing depth. Thereafter, the corresponding code representation graph is generated according to the above settings through the Joern code analysis tool. By generating a code representation graph according to the slicing depth set by the slicing strategy, path explosion can be prevented and the generation efficiency of the code representation graph can be effectively improved.
[0069] S42: extracting vulnerability-related variables and vulnerability-related program statements from the vulnerability-related slicing standard tuple <vulnerability-related variables, vulnerability-related program statements>, and locating corresponding nodes of the vulnerability-related variables and vulnerability-related program statements in the code representation graph;
[0070] Specifically, the generated code representation graph is read, and the nodes at the same position in the code representation graph are matched according to the positions of the vulnerability-related program statements in the file. The successfully matched nodes are considered to be the corresponding nodes of the vulnerability-related variables and the vulnerability-related program statements in the code representation graph.
[0071] S43: acquiring slicing-related nodes according to 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 relationship between the nodes of the code representation graph;
[0072] Specifically, the generated code representation graph is read, the edges and nodes related to the edges 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 vulnerability-related variables and vulnerability-related 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, and the acquired nodes are considered to be slicing-related nodes. By slicing according to the adaptive slicing direction, the code most relevant to the vulnerability part can be effectively found according to different vulnerability types, ensuring the reliability and effectiveness of the slicing results.
[0073] S44: extracting program statements corresponding to the slice-related nodes in the program, and considering that all the extracted program statements constitute preliminary program slicing results.
[0074] Specifically, the slice-related nodes and program files are read, the code lines where the slice-related nodes are located are extracted, and the corresponding program statements of the slice-related nodes in the program files are extracted according to the code line information, and all the extracted program statements are arranged according to the line numbers of the code lines of the program files where they are located to form a preliminary program slicing result.
[0075] S5: using a large language model to determine the integrity of the preliminary program slicing result, and obtaining a preliminary slicing integrity analysis result;
[0076] Specifically, we design a prompting template specifically for the large language model to judge the integrity of the code related to the vulnerability, integrate the program slicing results into the prompting template, use the API to call the large language model, and obtain the integrity analysis of the program slicing by the large language model. Through the integrity analysis of program slicing by the large language model, on the one hand, the slicing process can be segmented to prevent the path explosion problem when slicing between processes due to excessive code volume, and on the other hand, it can effectively determine whether the existing slicing results are complete, and then determine whether slicing needs to continue, to ensure the integrity of program slicing.
[0077] S6: Based on the preliminary slicing integrity analysis result and the preliminary program slicing result, a further slicing strategy is constructed, and further program slicing is performed on the program to obtain a final program slicing result. This step may include the following sub-steps:
[0078] S61: If the preliminary slicing integrity analysis result is that the program slicing is complete, the preliminary program slicing result is considered to be the final program slicing result, and program slicing ends;
[0079] Specifically, based on the integrity analysis of the preliminary slicing results, if the integrity analysis result shows that the program slicing is complete, no further slicing operation will be performed, and the result will be used as the final program slicing result to ensure the efficiency and accuracy of the slicing process.
[0080] S62: If the preliminary slicing integrity analysis result is that the program slicing is incomplete, further analyzing the preliminary program slicing result through a large language model, constructing an inter-procedural slicing strategy, and considering the inter-procedural slicing strategy as the further program slicing strategy;
[0081] Specifically, the prompt template for constructing the slicing strategy of the large language model is supplemented with the preliminary program slicing results and the vulnerability types repaired by the patch, and the large language model is called through the API to obtain the analysis results of the large language model for further program slicing strategies. After that, by analyzing the natural language response format of the large language model, the analysis results of the large language model for slicing direction, code representation graph type, and slicing depth are extracted, and the <slicing direction, code representation graph type, slicing depth> triple is constructed based on the result and saved in a dictionary format. Through this process, the comprehensiveness and accuracy of program slicing are guaranteed, providing a reliable foundation for developers to analyze and repair vulnerabilities.
[0082] S63: Perform further program slicing on the program according to the preliminary program slicing result and the further program slicing strategy to obtain a further program slicing result; this step may include the following sub-steps:
[0083] S631: Generate a code representation graph of a corresponding type under the program slicing depth setting according to the code representation graph type and slicing depth in the triplet <slicing direction, code representation graph type, slicing depth> of the further program slicing strategy.
[0084] Specifically, according to the slicing direction of the further program slicing strategy, determine whether the slicing orientation is forward slicing, backward slicing or bidirectional slicing; according to the code representation graph type, determine whether the code representation graph based on slicing is a control flow graph, a data flow graph, a program dependency graph, a code dependency graph or a function call graph; according to the slicing depth, determine whether the slicing range limited by the slicing depth is intra-file slicing or cross-file slicing. Thereafter, the corresponding code representation graph is generated according to the above settings through the Joern code analysis tool. By generating a code representation graph according to the slicing depth set by the slicing strategy, path explosion can be prevented and the generation efficiency of the code representation graph can be effectively improved.
[0085] S632: constructing a tuple of <variable in program statement, program statement in preliminary program slicing result> as a slicing standard according to the program statement in the preliminary program slicing result and the variables in the program statement;
[0086] Specifically, each program statement in the preliminary program slicing result is extracted, and each extracted program statement is analyzed using ClangAST to obtain the abstract syntax graph of the program statement, and then the variables in the program statement are extracted according to the node attributes in the abstract syntax graph. The extracted variables are considered to be variables in the program statements of the preliminary program slicing, and the extracted program statements are program statements in the preliminary program slicing result. A two-tuple of <variable in program statement, program statement in preliminary program slicing result> is constructed and saved as a slicing standard for further program slicing.
[0087] S633: According to the slicing standard, locate the corresponding nodes of the program statements and the variables in the program statements in the preliminary program slicing result in the code representation graph;
[0088] Specifically, the generated code representation graph is read, and the nodes at the same position in the code representation graph are matched according to the positions of the program statements in the preliminary program slicing results in the file. The nodes that are successfully matched are considered to be the variables in the program statements and the corresponding nodes in the code representation graph of the program statements in the preliminary program slicing results.
[0089] S634: Acquire slicing-related nodes according to the corresponding nodes in the code representation graph, the slicing direction of the further program slicing strategy, and the directed relationship between the nodes of the code representation graph;
[0090] Specifically, the generated code representation graph is read, and the edges and nodes related to the edges in the code representation graph are extracted and represented as <previous node, next node, edge type> edge relationship triples. Starting from 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, nodes are acquired along the edges of the code representation graph according to the slicing direction and the obtained edge relationship triples, and the acquired nodes are considered to be slicing-related nodes.
[0091] S635: extracting program statements corresponding to the slice-related nodes in the program, and considering that all the extracted program statements constitute further program slice results;
[0092] Specifically, the slice-related nodes and program files are read, the code lines where the slice-related nodes are located are extracted, and the corresponding program statements of the slice-related nodes in the program files are extracted according to the code line information, and all the extracted program statements are arranged according to the line numbers of the code lines of the program files where they are located to form further program slicing results.
[0093] S64: using a large language model to determine the integrity of the further program slicing result, and obtaining a further slicing integrity analysis result;
[0094] Specifically, the further program slicing results are integrated into a prompt template specifically used for the large language model to judge the integrity of the vulnerability-related code. The large language model is called using an API to obtain the integrity analysis of the further program slicing by the large language model, and obtain the further slicing integrity analysis results.
[0095] S65: If the further slicing integrity analysis result is that the program slicing is complete, the further program slicing result is considered to be the final program slicing result, and the program slicing ends;
[0096] Specifically, the large language model is used to perform integrity analysis on the further program slicing results to confirm that the slicing results have covered all necessary code paths and logics and that there are no missing parts. If the analysis results show that the program slicing is complete, the further program slicing results are considered the final result, and the program slicing process ends, ensuring the efficiency and accuracy of the final slicing results.
[0097] S66: If the further slicing integrity analysis result is that the program slicing is incomplete, the further program slicing result is considered to be a preliminary program slicing result, and this step is continued until the further slicing integrity analysis result is that the program slicing is complete;
[0098] Specifically, based on the results of further slicing integrity analysis, the missing parts and problem areas identified by the large language model are used to readjust and optimize the slicing strategy. The current further program slicing results are used as the new preliminary program slicing results, and all sub-steps in step S6 are repeated to continue slicing and integrity analysis. This process will continue to iterate until the large language model confirms that the program slicing results are complete, covering all necessary code paths and logic, and finally obtaining complete program slicing results. By judging the integrity of the sliced code fragments in stages and performing slicing operations step by step, it is possible to effectively prevent the explosion of slice paths and ensure the high integrity of sliced code fragments.
[0099] It can be seen from the above embodiments that the present application can accurately identify program statements directly related to vulnerabilities by using a large language model to screen and analyze program statements in patches, thereby accurately determining vulnerability-related slicing standards. By automatically determining the type of vulnerability repaired by the patch and building appropriate slicing strategies for different vulnerability features, slicing according to the characteristics of different vulnerabilities can be achieved, achieving the effect of efficiently obtaining complete slice codes related to the vulnerability. By judging the integrity of the slice code fragments, slicing is performed in stages, ensuring the high integrity of the slice code fragments while preventing the slice path from exploding.
[0100] Corresponding to the aforementioned embodiment of the vulnerability type adaptive program slicing method, the present application also provides an embodiment of the vulnerability type adaptive program slicing device.
[0101] Figure 2 is a block diagram of a vulnerability type adaptive program slicing device according to an exemplary embodiment. Figure 2 , the device comprises:
[0102] The patch collection module 1 is used to collect patches, extract patch descriptions and program statements in the patches, and use patch analysis tools and vulnerability repair patch identification tools to screen the patches to obtain patches that repair program vulnerabilities;
[0103] Slicing standard extraction module 2, used for screening program statements in the patch for fixing the program vulnerability by using a large language model, and obtaining program statements related to the vulnerability as vulnerability-related slicing standards;
[0104] Slicing strategy building module 3, used to use a large language model to determine the vulnerability type of the patch repair based on the patch description and the program statements in the patch, and to build a preliminary slicing strategy for different vulnerability features;
[0105] A 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 preliminary program slicing results;
[0106] An integrity analysis module 5 is used to determine the integrity of the preliminary program slicing result using a large language model to obtain a preliminary slicing integrity analysis result;
[0107] The further program slicing module 6 is used to construct a further slicing strategy based on the preliminary slicing integrity analysis result and the preliminary program slicing result, and to perform further program slicing on the program to obtain a final program slicing result.
[0108] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0109] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present application scheme. A person of ordinary skill in the art can understand and implement it without paying any creative work.
[0110] Accordingly, the present application also provides an electronic device, comprising: one or more processors; a memory for storing 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 vulnerability type adaptive program slicing method as described above. Figure 3 As shown, a hardware structure diagram of any device with data processing capability in which a vulnerability type adaptive program slicing device provided by 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 device with data processing capabilities in which the apparatus in the embodiment is located may also include other hardware, which will not be described in detail, generally based on the actual functions of the device with data processing capabilities.
[0111] Accordingly, the present application also provides a computer-readable storage medium on which computer instructions are stored, and when the instructions are executed by the processor, the vulnerability type adaptive program slicing method as described above is implemented. The computer-readable storage medium can be an internal storage unit of any device with data processing capabilities described in any of the aforementioned embodiments, such as a hard disk or a memory. The computer-readable storage medium can also be an external storage device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), an SD card, a flash card (Flash Card), etc. equipped on the device. Furthermore, the computer-readable storage medium can also include both an internal storage unit and an external storage device of any device with data processing capabilities. The computer-readable storage medium is used to store the computer program and other programs and data required by any device with data processing capabilities, and can also be used to temporarily store data that has been output or is to be output.
[0112] Those skilled in the art will readily appreciate other embodiments of the present application after considering the description and practicing the contents disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The description and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the claims.
[0113] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A vulnerability type adaptive program slicing method, It is characterized in that include: Collect patches, extract patch descriptions and program statements in the patches, and use patch analysis tools and vulnerability repair patch identification tools to screen the patches to obtain patches that repair program vulnerabilities; Using a large language model to screen program statements in the patch for fixing the program vulnerability, and obtaining program statements related to the vulnerability as vulnerability-related slicing standards; Using a large language model to determine the vulnerability type to be repaired by the patch description and program statements in the patch, and constructing a preliminary slicing strategy for different vulnerability features; According to the vulnerability-related slicing standard and the preliminary slicing strategy, the program is sliced in-process to obtain the in-process program slice, and the in-process program slice is considered to be the preliminary program slicing result; Using a large language model to determine the integrity of the preliminary program slicing result, to obtain a preliminary slicing integrity analysis result; Based on the preliminary slicing integrity analysis result and the preliminary program slicing result, a further slicing strategy is constructed, and the program is further sliced to obtain a final program slicing result.
2. The method according to claim 1, It is characterized in that Collect patches, extract patch descriptions and program statements in the patches, and use patch analysis tools and vulnerability repair patch identification tools to screen the patches to obtain patches that repair program vulnerabilities, including: Use distributed version control tools to collect patches; Analyzing the patch using a patch analysis tool to extract a patch description of the patch and program statements in the patch; The patch description and program statements in the patch are screened by applying a vulnerability repair patch identification tool, a keyword matching method and a natural language processing method to obtain a patch that repairs the vulnerability.
3. The method according to claim 1, It is characterized in that The program statements in the patch are screened using a large language model to obtain program statements related to the vulnerability as vulnerability-related slicing standards, including: Design a prompt template for analyzing program statements related to large language model vulnerabilities; Integrate the patch description and program statements in the patch for fixing the program vulnerability into a prompting template, and use a large language model to determine the vulnerability relevance of each program statement in the patch; According to the vulnerability correlation judgment result, program statements in the patch are screened to obtain program statements related to the vulnerability; Applying a variable identification tool to extract relevant variables in the program statement related to the vulnerability, and considering the variable as a vulnerability-related variable in the program statement; Construct a <vulnerability-related variable, vulnerability-related program statement> tuple as the vulnerability-related slicing standard.
4. The method according to claim 1, It is characterized in that The patch description and program statements in the patch are used to determine the vulnerability type of the patch, and a preliminary slicing strategy is constructed for different vulnerability features, including: Design a prompt template for judging the vulnerability type of a large language model; Integrate the patch description of the patch, the program statements in the patch, and the program statements related to the vulnerability into the vulnerability type judgment prompt template, apply the large language model to judge the type of vulnerability repaired by the patch, and obtain the type of vulnerability repaired by the patch; The large language model is used to further analyze the patch description of the patch, the program statements related to the vulnerability, and the vulnerability type fixed by the patch to build a slicing strategy.
5. The method according to claim 4, It is characterized in that The patch description, program statements related to the vulnerability, and the vulnerability type fixed by the patch are further analyzed using a large language model to construct a slicing strategy, including: Designing prompt templates for building slicing strategies for large language models; Integrate the patch description of the patch, the program statements related to the vulnerability, and the vulnerability type fixed by the patch into the prompting template for constructing the slicing strategy, and apply the large language model to perform slicing strategy analysis; The slicing strategy analysis result is extracted to construct a <slicing direction, code representation graph type, slicing depth> triple as the constructed slicing strategy.
6. The method according to claim 1, It is characterized in that According to the vulnerability-related slicing standard and the preliminary slicing strategy, the program is sliced in-process to obtain the in-process program slice, and the in-process program slice is considered to be the preliminary program slicing result, including: According to the code representation graph type and slicing depth in the <slicing direction, code representation graph type, slicing depth> triplet of the preliminary slicing strategy, a code representation graph of the corresponding type under the program slicing depth setting is generated; Extracting vulnerability-related variables and vulnerability-related program statements from the vulnerability-related slicing standard tuple <vulnerability-related variables, vulnerability-related program statements>, and locating corresponding nodes of the vulnerability-related variables and vulnerability-related program statements in the code representation graph; Obtaining slicing-related nodes according to 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 relationship between the nodes of the code representation graph; Program statements corresponding to the slice-related nodes in the program are extracted, and it is considered that all the extracted program statements constitute preliminary program slicing results.
7. The method according to claim 1, It is characterized in that According to the preliminary slicing integrity analysis result and the preliminary program slicing result, a further slicing strategy is constructed, and the program is further sliced to obtain a final program slicing result, including: If the preliminary slicing integrity analysis result is that the program slicing is complete, the preliminary program slicing result is considered to be the final program slicing result, and the program slicing is terminated; If the preliminary slicing integrity analysis result is that the program slicing is incomplete, further analyzing the preliminary program slicing result through a large language model, constructing an inter-procedural slicing strategy, and considering the inter-procedural slicing strategy as the further program slicing strategy; According to the preliminary program slicing result and the further program slicing strategy, further program slicing is performed on the program to obtain a further program slicing result; Using a large language model to determine the integrity of the further program slicing result, and obtaining a further slicing integrity analysis result; If the further slicing integrity analysis result is that the program slicing is complete, the further program slicing result is considered to be the final program slicing result, and the program slicing is terminated; If the further slicing integrity analysis result is that the program slicing is incomplete, the further program slicing result is considered to be a preliminary program slicing result, and this step is continued until the further slicing integrity analysis result is that the program slicing is complete.
8. The method according to claim 7, It is characterized in that According to the preliminary program slicing result and the further program slicing strategy, the program is sliced to obtain a further program slicing result, including: Generate a code representation graph of a corresponding type under the program slicing depth setting according to the code representation graph type and slicing depth in the <slicing direction, code representation graph type, slicing depth> triplet of the further program slicing strategy; According to the program statements in the preliminary program slicing result and the variables in the program statements, construct a two-tuple of <variable in the program statement, program statement in the preliminary program slicing result> as a slicing standard; According to the slicing standard, locate the corresponding nodes of the program statements and the variables in the program statements in the preliminary program slicing result in the code representation graph; Obtaining slicing-related nodes according to corresponding nodes in the code representation graph, a slicing direction of a further program slicing strategy, and directed relationships between nodes in the code representation graph; Program statements corresponding to the slice-related nodes in the program are extracted, and it is considered that all the extracted program statements constitute further program slicing results.
9. A vulnerability type adaptive program slicing device, It is characterized in that include: A patch collection module is used to collect patches, extract patch descriptions and program statements in the patches, and use patch analysis tools and vulnerability repair patch identification tools to screen the patches to obtain patches that repair program vulnerabilities; A slicing standard extraction module is used to screen the program statements in the patch for fixing the program vulnerability using a large language model, and obtain program statements related to the vulnerability as vulnerability-related slicing standards; A slicing strategy building module is used to use a large language model to determine the vulnerability type of the patch repair based on the patch description and the program statements in the patch, and to build a preliminary slicing strategy for different vulnerability features; A preliminary program slicing module, used to perform intra-process slicing on the program according to the vulnerability-related slicing standard and the preliminary slicing strategy, obtain intra-process program slices, and consider the intra-process program slices as preliminary program slicing results; An integrity analysis module, used to determine the integrity of the preliminary program slicing result using a large language model to obtain a preliminary slicing integrity analysis result; The further program slicing module is used to construct a further slicing strategy based on the preliminary slicing integrity analysis result and the preliminary program slicing result, and to perform further program slicing on the program to obtain a final program slicing result.
10. An electronic device, It is characterized in that include: one or more processors; A memory for storing 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 according to any one of claims 1 to 8.
Citation Information
Patent Citations
Large-scale software vulnerability detection method and system adopting vulnerability slices
CN114186240A
Method and device for identifying vulnerability information of terminal of power internet of things
CN115952510A
Improved source code slicing method based on context edge relation
CN117171029A
Code defect analysis method and device
CN117171741A
System and method for auto repairing vulnerable code program fragments of a software
EP4386601A1
Cited By
Method and system for automatically generating and labeling vulnerability program
CN119670099A
