Buffer overflow vulnerability detection method and device, storage medium and computer equipment

By generating positive and negative prompt sample sets and using a large language model to detect buffer overflow vulnerabilities, the problem of low buffer overflow vulnerability detection accuracy in the existing technology is solved, more accurate and efficient vulnerability detection is achieved, and detection is enhanced. Interpretability of results.

CN118656835APending Publication Date: 2024-09-17SUN YAT SEN UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411012328.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-26
Publication Date
2024-09-17

AI Technical Summary

Technical Problem

The accuracy of existing buffer overflow vulnerability detection methods is not high, mainly because they rely on vulnerability patterns manually generated by human experts, resulting in incomplete pattern coverage and causing false positives or false negatives.

Method used

By obtaining the target source code, extracting the first dangerous code slice and the second dangerous code slice, generating a positive prompt sample set and a negative prompt sample set, using a large language model to detect buffer overflow vulnerabilities, combined with the thinking chain derivation process, to improve the detection accuracy Personalized and targeted.

Benefits of technology

The accuracy and efficiency of buffer overflow vulnerability detection are improved, potential buffer overflow vulnerabilities can be discovered more accurately, and the interpretability and credibility of detection results are enhanced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118656835A
    Figure CN118656835A
Patent Text Reader

Abstract

According to the buffer overflow vulnerability detection method and device, the storage medium and the computer equipment provided by the invention, a target source code is acquired, and each first dangerous code slice, each second dangerous code slice and a to-be-detected code slice are extracted from the target source code; generating a positive prompt sample set according to each first danger code slice and a preset first thinking chain derivation process corresponding to each first danger code slice, and generating a negative prompt sample set according to each second danger code slice and each preset second thinking chain derivation process; and inputting the positive prompt sample set, the negative prompt sample set and the to-be-detected code slice into a large language model to obtain a buffer overflow vulnerability detection result of the to-be-detected code slice. In this way, the accuracy of buffer overflow vulnerability detection can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a buffer overflow vulnerability detection method, device, storage medium and computer equipment. Background Art

[0002] Buffer overflow vulnerabilities are a common security vulnerability that often occurs in operating systems, compilers, drivers, and embedded systems. Buffer overflow vulnerabilities may cause attackers to execute malicious code, destroying the integrity and security of the system. Buffer overflow vulnerabilities are also an important reason for the prevalence of network attacks. Some dangerous codes in the source code may have the risk of buffer overflow vulnerabilities, while some dangerous codes will not cause buffer overflow vulnerabilities. Therefore, by accurately detecting and analyzing buffer overflow vulnerabilities, potential security vulnerabilities in the system can be discovered early, and corresponding repair and prevention measures can be taken in time to prevent buffer overflow vulnerabilities from being maliciously attacked.

[0003] At present, commonly used buffer overflow vulnerability detection is mainly divided into rule-based, machine learning-based and deep learning-based detection methods. In the rule-based, machine learning-based and deep learning-based detection methods, buffer overflow vulnerability detection is performed through pre-defined vulnerability patterns, which can help detect buffer overflow vulnerabilities to a certain extent. However, these vulnerability patterns are usually manually generated by human experts. Because they rely too much on human experts to manually define vulnerability patterns, they may be affected by incomplete pattern coverage, thereby causing false positives or negatives, resulting in low accuracy of buffer overflow vulnerability detection. Summary of the invention

[0004] The purpose of this application is to solve at least one of the above-mentioned technical defects, especially the technical defect that the accuracy of buffer overflow vulnerability detection in the prior art is not high.

[0005] In a first aspect, the present application provides a buffer overflow vulnerability detection method, the method comprising:

[0006] Obtaining a target source code, and extracting each first dangerous code slice, each second dangerous code slice, and a code slice to be detected from the target source code, wherein the first dangerous code slice is used to form a buffer overflow vulnerability, and the second dangerous code slice is used not to form a buffer overflow vulnerability;

[0007] A positive prompt sample set is generated according to each first dangerous code slice and the preset first thought chain derivation process corresponding to each first dangerous code slice, and a negative prompt sample set is generated according to each second dangerous code slice and each preset second thought chain derivation process, the first thought chain derivation process is used to analyze whether the corresponding first dangerous code slice causes a buffer overflow vulnerability, and the second thought chain derivation process is used to analyze whether the corresponding second dangerous code slice does not form a buffer overflow vulnerability, and the positive prompt sample set and the negative prompt sample set are used to prompt the large language model to perform a buffer overflow vulnerability detection task on the code slice to be detected;

[0008] The positive prompt sample set, the negative prompt sample set and the code slice to be detected are input into the large language model to obtain the buffer overflow vulnerability detection result of the code slice to be detected.

[0009] In one embodiment, the step of extracting each first dangerous code slice and each second dangerous code slice from the target source code includes:

[0010] Determine a plurality of dangerous code types corresponding to the buffer overflow vulnerability code, and determine a retrieval method corresponding to each dangerous code type;

[0011] Using various search methods to search the target source code to determine the target dangerous code corresponding to each dangerous code type;

[0012] Through data flow analysis and control flow analysis, the first danger code and the second danger code are extracted from each target danger code, and each first danger code is sliced ​​and extracted to obtain each first danger code slice, and each second danger code is sliced ​​and extracted to obtain each second danger code slice.

[0013] In one embodiment, the dangerous code types include library / API function call types, array types, pointer types, and arithmetic expression types, and the step of determining the retrieval method corresponding to each dangerous code type includes:

[0014] For each hazard code type, determine a text template list corresponding to the hazard code type;

[0015] According to the text template lists corresponding to the library / API function call type and the arithmetic expression type, the text matching method is used as the retrieval method of the library / API function call type and the arithmetic expression type;

[0016] According to the text template list corresponding to the array type and the pointer type, the text matching method and the abstract syntax tree method are used as the retrieval method of the array type and the pointer type.

[0017] In one embodiment, the steps of slicing and extracting each first danger code to obtain each first danger code slice, and slicing and extracting each second danger code to obtain each second danger code slice include:

[0018] Determining a data flow and a control flow for each first hazard code, and determining a data flow and a control flow for each second hazard code;

[0019] Extracting the code line where the data flow and control flow of each first dangerous code are located by using a graph traversal method, and extracting the code line where the data flow and control flow of each second dangerous code are located;

[0020] The code lines corresponding to each first dangerous code are spliced ​​according to the program execution order in the target source code to obtain each first dangerous code slice, and the code lines corresponding to each second dangerous code are spliced ​​to obtain each second dangerous code slice.

[0021] In one embodiment, the process of constructing the positive prompt sample set and the negative prompt sample set includes:

[0022] Extracting a plurality of features of each first dangerous code slice and a plurality of features of each second dangerous code slice respectively;

[0023] Based on the clustering algorithm, clustering each first dangerous code slice according to multiple features of each first dangerous code slice to obtain multiple first cluster centers, and clustering each second dangerous code slice according to multiple features of each second dangerous code slice to obtain multiple second cluster centers;

[0024] Obtain the first thought chain deduction process corresponding to each first cluster center, and the second thought chain deduction process corresponding to each second cluster center, and use each first cluster center and the corresponding thought chain deduction process as a positive prompt sample set, and use each second cluster center and the corresponding thought chain deduction process as a negative prompt sample set.

[0025] In one embodiment, the positive prompt sample set further includes the line number corresponding to each first dangerous code slice, the negative prompt sample set further includes the line number corresponding to each second dangerous code slice, and the method further includes:

[0026] Determine the line number corresponding to the code slice to be detected, and input the positive prompt sample set, the negative prompt sample set, the code slice to be detected and the line number corresponding to the code slice to be detected into the large language model to obtain the buffer overflow vulnerability detection result of the code slice to be detected.

[0027] In a second aspect, the present application provides a large language model training method, comprising:

[0028] Assigning a label value for indicating the existence of a buffer overflow vulnerability to a positive prompt sample set, and assigning a label value for indicating the absence of a buffer overflow vulnerability to a negative prompt sample set, the positive prompt sample set being the positive prompt sample set in the buffer overflow vulnerability detection method of any of the above embodiments, and the negative prompt sample set being the negative prompt sample set in the buffer overflow vulnerability detection method of any of the above embodiments;

[0029] Dividing the positive prompt sample set into a first training subset and a first test subset, and dividing the negative prompt sample set into a second training subset and a second test subset, and using the first training subset and the second training subset as training sets, and using the first test subset and the second test subset as test sets;

[0030] The initial large language model is iteratively trained using a training set and a test set. When the trained initial large language model meets a preset training end condition, a large language model is obtained.

[0031] In a third aspect, the present application provides a buffer overflow vulnerability detection device, the device comprising:

[0032] A target source code acquisition module is used to acquire the target source code and extract each first dangerous code slice, each second dangerous code slice and a code slice to be detected from the target source code, wherein the first dangerous code slice is used to form a buffer overflow vulnerability, and the second dangerous code slice is used not to form a buffer overflow vulnerability;

[0033] A prompt sample set generation module is used to generate a positive prompt sample set according to each first dangerous code slice and a preset first thought chain derivation process corresponding to each first dangerous code slice, and to generate a negative prompt sample set according to each second dangerous code slice and each preset second thought chain derivation process. The first thought chain derivation process is used to analyze whether the corresponding first dangerous code slice causes a buffer overflow vulnerability, and the second thought chain derivation process is used to analyze whether the corresponding second dangerous code slice does not form a buffer overflow vulnerability. The positive prompt sample set and the negative prompt sample set are used to prompt the large language model to perform a buffer overflow vulnerability detection task on the code slice to be detected;

[0034] The dangerous code detection module is used to input the positive prompt sample set, the negative prompt sample set and the code slice to be detected into the large language model to obtain the buffer overflow vulnerability detection result of the code slice to be detected.

[0035] In a fourth aspect, the present application provides a storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the buffer overflow vulnerability detection method of any of the above-mentioned embodiments, and / or the steps of the large language model training method of the above-mentioned embodiments.

[0036] In a fifth aspect, the present application provides a computer device, comprising: one or more processors, and a memory;

[0037] Computer-readable instructions are stored in the memory. When the computer-readable instructions are executed by one or more processors, the buffer overflow vulnerability detection method of any of the above-mentioned embodiments and / or the steps of the large language model training method of the above-mentioned embodiments are performed.

[0038] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:

[0039] In the buffer overflow vulnerability detection method, device, storage medium and computer equipment provided by the present application, a positive prompt sample set and a negative prompt sample set are used to prompt the large language model, so that it can learn for a specific buffer overflow vulnerability pattern, so that the model obtained by the prompt is more suitable for the code slice to be detected to detect the buffer overflow vulnerability. At the same time, the positive prompt sample set, the negative prompt sample set and the code slice to be detected are all derived from the same source code, thereby improving the personalization and pertinence of the detection. The positive and negative prompt sample sets also include the corresponding thinking chain reasoning process, and are input into the large language model as prompt content, so that the large language model can fully understand the semantics and context of the source code. In this way, based on the positive and negative prompt sets, the large language model is guided to perform buffer overflow vulnerability detection on the code fragment to be detected, and potential buffer overflow vulnerabilities can be more accurately discovered. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0041] Figure 1 A schematic diagram of a process for detecting a buffer overflow vulnerability provided by an embodiment of the present application;

[0042] Figure 2 Schematic diagram of a large language model training method provided in an embodiment of the present application

[0043] Figure 3 A schematic diagram of the structure of a buffer overflow vulnerability detection device provided in an embodiment of the present application;

[0044] Figure 4 A schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0045] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0046] The present application provides a buffer overflow vulnerability detection method. The following embodiments are described by taking the method applied to a computer device as an example. It can be understood that the computer device can be any device with data processing functions, including but not limited to a single server, a server cluster, a personal laptop computer, a desktop computer, etc. Figure 1 As shown, the method includes:

[0047] S101: Obtain a target source code, and extract each first dangerous code slice, each second dangerous code slice, and a code slice to be detected from the target source code.

[0048] Among them, the first dangerous code slice refers to a dangerous code slice used to form a buffer overflow vulnerability, and the second dangerous code slice refers to a dangerous code slice used not to form a buffer overflow vulnerability. The target source code refers to the source code of a specific software or program that analyzes and detects whether there is a buffer overflow vulnerability. A dangerous code slice refers to a code fragment in the target source code that has a potential security vulnerability or may cause security issues, and may include but is not limited to code fragments of the types of buffer overflow, code injection, and security vulnerability. The code slice to be detected refers to a dangerous code slice in the target source code that is used to analyze and detect whether there is a buffer overflow vulnerability.

[0049] In this step, you first need to obtain the source code of the target software or program, which can be obtained through legal means, such as from an open source code library. After that, perform code analysis on the target source code to identify potential security vulnerabilities and risk points. During the code analysis process, mark and determine potential dangerous code slices. Specifically, the dangerous code slice that is determined to be able to form a buffer overflow vulnerability can be used as the first dangerous code slice, the dangerous code slice that is determined not to be able to form a buffer overflow vulnerability can be used as the second dangerous code slice, and the dangerous code slice that is uncertain whether it can form a buffer overflow vulnerability can be used as the dangerous code slice to be detected.

[0050] S102: Generate a positive prompt sample set according to each first danger code slice and a preset first thinking chain derivation process corresponding to each first danger code slice, and generate a negative prompt sample set according to each second danger code slice and each preset second thinking chain derivation process.

[0051] Among them, the first thinking chain deduction process is used to analyze the corresponding first dangerous code slice to cause a buffer overflow vulnerability, and the second thinking chain deduction process is used to analyze the corresponding second dangerous code slice to not form a buffer overflow vulnerability. The positive prompt sample set and the negative prompt sample set are used to prompt the large language model to perform buffer overflow vulnerability detection tasks on the code slice to be detected.

[0052] Among them, the large language model refers to a huge neural network model, which is usually built based on deep learning technology and can handle the generation, understanding and reasoning tasks of natural language text. The thinking chain refers to a series of logical reasoning or reasoning chains in the cognitive process, which is used to describe the thinking mode and steps of humans when solving problems or making decisions. Specifically, the thinking chain can be the logical reasoning process used to reason whether a dangerous code slice will cause a buffer overflow vulnerability, and the logical reasoning process used to analyze dangerous code slices that will not cause a buffer overflow vulnerability.

[0053] In this step, first, the first dangerous code slices used to form a buffer overflow vulnerability are collected. The first dangerous code slices should contain malicious code fragments that can trigger the buffer overflow vulnerability, and the second dangerous code slices used not to form a buffer overflow vulnerability are collected. The malicious code fragments contained in the second dangerous code slices cannot trigger the buffer overflow vulnerability. Then, a corresponding thinking chain reasoning process is constructed for each first dangerous code slice, and how it causes the occurrence of a buffer overflow vulnerability is analyzed, and each first dangerous code slice and the corresponding thinking chain deduction process are used as a positive prompt sample set, and a thinking chain reasoning process is constructed for each second dangerous code slice to explain why it does not cause the occurrence of a buffer overflow vulnerability, and each second dangerous code slice and the corresponding thinking chain deduction process are used as a negative prompt sample set. By using positive and negative prompt sample sets to prompt the large language model, the large language model can learn how to effectively identify potential buffer overflow vulnerabilities in the dangerous code to be detected.

[0054] Furthermore, the collected data can be preprocessed, including text cleaning, tokenization, vectorization and other operations, so as to facilitate input into the large language model for prompting, and features related to buffer overflow vulnerabilities can be extracted to help the model better learn and understand the associations between samples. Then, the target large language model is prompted with positive prompt sample sets and negative prompt sample sets, so that it can identify potential buffer overflow vulnerabilities and analyze the thought chain reasoning process.

[0055] It is understandable that one of the reasons for using a large language model to detect code buffer overflow vulnerabilities is its powerful context understanding ability. By learning code structure and semantics through training data, the large language model can deeply understand the context and language of code snippets, thereby more accurately identifying potential security risks. Its learning ability enables it to make judgments on buffer overflow problems in the code, providing strong support for code security detection. On the other hand, using thinking chains to detect code buffer overflow vulnerabilities can improve the interpretability and logical analysis capabilities of the judgment results. Thinking chains can explain the logical inference process of the model's judgment results, help users understand the root cause of the judgment results, and track the basis of the model's judgment. This logical analysis process enhances the credibility of the model's judgment results and helps to reveal potential buffer overflow problems. Finally, combining large language models and thinking chains to detect code buffer overflow vulnerabilities can give full play to the advantages of both. The combination of the intelligent judgment ability of the large language model and the logical analysis of the thinking chain not only improves the reliability of the detection system, but also enhances the interpretability of the detection results. Through comprehensive application, the accuracy and efficiency of code buffer overflow vulnerability detection can be improved, providing comprehensive protection for code security detection.

[0056] S103: Input the positive prompt sample set, the negative prompt sample set and the code slice to be detected into the large language model to obtain the buffer overflow vulnerability detection result of the code slice to be detected.

[0057] In this step, when performing the buffer overflow vulnerability detection task, the positive prompt sample set, the negative prompt sample set, and the code slice to be detected can be input into the large language model to obtain the detection result of the buffer overflow vulnerability of the code slice to be detected. The positive prompt sample set contains code slices that are known to have buffer overflow vulnerabilities, which are used to prompt the large language model to learn the characteristics and patterns of these vulnerabilities. The negative prompt sample set contains code slices that will not cause buffer overflows, helping the model to distinguish the difference between normal code and potential vulnerability code. The code slice to be detected is the target that needs to be detected for buffer overflow vulnerabilities. By inputting it into the large language model that is prompted with positive and negative prompt sample sets, the model can evaluate whether the code slice has a potential buffer overflow risk based on the learned knowledge and patterns, and output the corresponding detection results.

[0058] In the above embodiment, positive prompt sample sets and negative prompt sample sets are used to prompt the large language model, so that it can learn specific buffer overflow vulnerability patterns, so that the model obtained by the prompt is more suitable for the code slice to be detected to detect buffer overflow vulnerabilities. At the same time, the positive prompt sample set, the negative prompt sample set and the code slice to be detected are all derived from the same source code, thereby improving the personalization and pertinence of the detection. The positive and negative prompt sample sets also include the corresponding thinking chain reasoning process, and are input into the large language model as prompt content, so that the large language model can fully understand the semantics and context of the source code. In this way, based on the positive and negative prompt sets, the large language model is guided to perform buffer overflow vulnerability detection on the code fragment to be detected, and potential buffer overflow vulnerabilities can be discovered more accurately.

[0059] In one embodiment, the step of extracting each first dangerous code slice and each second dangerous code slice from the target source code includes:

[0060] Determine a plurality of dangerous code types corresponding to the buffer overflow vulnerability code, and determine a retrieval method corresponding to each dangerous code type;

[0061] Using various search methods to search the target source code to determine the target dangerous code corresponding to each dangerous code type;

[0062] Through data flow analysis and control flow analysis, the first danger code and the second danger code are extracted from each target danger code, and each first danger code is sliced ​​and extracted to obtain each first danger code slice, and each second danger code is sliced ​​and extracted to obtain each second danger code slice.

[0063] Among them, the dangerous code type refers to the code pattern corresponding to the dangerous code with buffer overflow vulnerabilities, including string type, array type and pointer type. The retrieval method refers to the method or technology used to find and identify specific dangerous code types in the target source code. The target dangerous code refers to the specific code fragment or code block that is determined to belong to a specific dangerous code type after retrieval and identification in the source code. Each target dangerous code may have potential buffer overflow vulnerabilities or other security risks. Data flow refers to the process of data items (such as variables, parameters, etc.) being transferred and changed between different statements during program execution. In data flow analysis, the use, transfer path and impact range of data in the program can be tracked to better understand the program behavior and perform static analysis. Control flow refers to the order and method of control flow transfer between statements when the program is executed. By analyzing the control flow, structures such as loops, conditional branches, function calls, etc. in the program can be identified to help understand the execution logic and possible execution paths of the code.

[0064] Specifically, multiple dangerous code types can be determined through coding standards and static code analysis tools. For each dangerous code type, the corresponding retrieval method can be determined by using static code analysis tools, code review, fuzz testing, etc., and then the determined retrieval method is used to search the target source code to ensure that all possible dangerous code types are covered. At the same time, for each dangerous code type, identify and record the potential dangerous code that conforms to this type in the target source code. Then, use data flow analysis and control flow analysis to determine whether each target dangerous code has a buffer overflow vulnerability. If so, the target dangerous code is determined as the first dangerous code, otherwise the target dangerous code is determined as the second dangerous code. After that, the program slicing technology can be used to extract the relevant parts of each first dangerous code and the second dangerous code, including data flow, control flow dependency, context information, etc., to obtain multiple first dangerous code slices and second dangerous code slices.

[0065] In this embodiment, by determining multiple dangerous code types and using different retrieval methods, potential security risks in source code can be comprehensively detected, the accuracy of detection can be improved, and all types of dangerous codes can be effectively discovered. After slicing and extracting the target dangerous code, the dependency relationship and context information between codes can be better understood, which helps to better locate the dangerous code.

[0066] In one embodiment, the dangerous code types include library / API function call types, array types, pointer types, and arithmetic expression types, and the step of determining the retrieval method corresponding to each dangerous code type includes:

[0067] For each hazard code type, determine a text template list corresponding to the hazard code type;

[0068] According to the text template lists corresponding to the library / API function call type and the arithmetic expression type, the text matching method is used as the retrieval method of the library / API function call type and the arithmetic expression type;

[0069] According to the text template list corresponding to the array type and the pointer type, the text matching method and the abstract syntax tree method are used as the retrieval method of the array type and the pointer type.

[0070] Among them, the library / API function call type refers to the function call of the external library or API used in the programming process. This type of dangerous code may have security vulnerabilities, such as security risks and memory leaks caused by unvalidated user input. The array type refers to the data structure used to store data elements of the same type in the program. When processing arrays, security issues such as out-of-bounds access, memory leaks, and buffer overflows may occur. The pointer type is used to store memory addresses. Pointer operations are prone to problems such as null pointer dereference, memory leaks, and wild pointers. The arithmetic expression type refers to expressions involving mathematical operations in the program, including addition, subtraction, multiplication, division, and logical operations. When writing arithmetic expressions, problems such as overflow, type conversion errors, and division by zero errors may occur.

[0071] Specifically, for library / API function call types and arithmetic expression types, common text templates such as function names, function parameters, operators, etc. are listed respectively. The source code is searched using text matching, and the library / API function calls and arithmetic expressions are located by finding matching text templates, thereby discovering potential dangerous code. For array types and pointer types, common text templates such as array names, pointer operators, array indexes, etc. are listed. The source code is searched using text matching, and array operations and pointer operations are located by finding matching text templates to discover possible security risks. At the same time, the Abstract Syntax Tree (AST) is used to parse the source code, identify the array operations and pointer operations therein, and further analyze the code structure in depth to discover potential problem codes.

[0072] Furthermore, when it comes to library / API function calls, retrieving relevant dangerous code in the source code usually relies on text matching and the accuracy of function names. Through text matching, specific function names or APIs used in the source code can be retrieved, and further evaluated based on the data dependencies and control dependencies of these function calls to see if there are vulnerabilities that may cause buffer overflows, so it is very important to identify these function calls and check how they are used. However, this approach may be affected by function aliases, renames, or abbreviations, so various naming variations need to be considered to ensure accuracy.

[0073] In terms of arrays and pointers, retrieving dangerous code in source code through abstract syntax tree (AST) and text matching can help identify potential buffer overflow vulnerability code. Array out-of-bounds access or unverified pointer operations are some common security risks. AST can help understand code structure and semantics, while text matching can locate specific array or pointer operations. This combination can help detect dangerous arrays and pointers that lead to buffer overflow vulnerabilities such as buffer overflow and null pointer reference.

[0074] When processing arithmetic expressions, searching for dangerous code in source code through text pattern matching usually involves identifying potential mathematical errors or overflow risks. This may include identifying integer overflow, division by zero, or inappropriate mathematical operations. By identifying these dangerous codes and performing subsequent data flow and control flow analysis, potential risks that may exist in the code can be discovered.

[0075] In this embodiment, the refined search method helps to accurately locate various types of dangerous codes, which is conducive to targeted solutions to various security risks and improves detection efficiency. For pointer types and array types, a combination of text matching and abstract syntax tree methods can be used to comprehensively review the source code and discover potential problems.

[0076] In one embodiment, the steps of performing slicing extraction on each first danger code to obtain each first danger code slice, and performing slicing extraction on each second danger code to obtain each second danger code slice include:

[0077] Determining a data flow and a control flow for each first hazard code, and determining a data flow and a control flow for each second hazard code;

[0078] A graph traversal method is used to extract the code line where the data flow and control flow of each first dangerous code are located, and a code line where the data flow and control flow of each second dangerous code are located is extracted;

[0079] The code lines corresponding to each first dangerous code are spliced ​​according to the program execution order in the target source code to obtain each first dangerous code slice, and the code lines corresponding to each second dangerous code are spliced ​​to obtain each second dangerous code slice.

[0080] Graph traversal refers to the process of visiting each node in the graph structure in sequence according to certain rules. In software engineering, the control flow and data flow of the code can be represented as a graph structure, and the structure and relationship of the code can be analyzed and traversed through graph traversal. Graph traversal algorithms include depth-first search (DFS) and breadth-first search (BFS), which can be used to find specific paths, relationships, or information transfer in the code.

[0081] Specifically, the source code can be analyzed for data flow and control flow using static code analysis tools such as Joern or manual analysis. Data flow analysis can track the data transfer path in the program, while control flow analysis can understand the execution order and conditional branches between program statements. By determining the data flow and control flow of each first dangerous code, as well as the data flow and control flow of each second dangerous code, the variables, statements and paths related thereto are found. Among them, the control flow and data flow can be stored in data such as neo4j. Afterwards, a graph traversal algorithm is used to traverse the graph structure starting from the starting node where the first dangerous code is located, and the code lines where the data flow and control flow related to the code are located are extracted. The code lines that have been passed are recorded during the traversal process so that code slices can be generated later. According to the program execution order in the target source code, the extracted code lines are spliced ​​in the execution order to form code slices corresponding to each first dangerous code. Similarly, the code slices corresponding to each second dangerous code can be obtained to ensure that the code lines are connected according to the logical execution flow of the program to accurately reflect the path and data flow during program execution.

[0082] In one example, corresponding to dangerous code for library / API function calls, arrays, pointers, and arithmetic expressions, dangerous code slices can be generated through data flow and control flow analysis of the program. For example, for library / API function calls, data flow analysis can track the path of parameter passing during function calls, which may lead to potential buffer overflow vulnerabilities if function parameters are not fully checked or processed; control flow analysis can reveal the possible execution paths of each parameter of the function call and the dependencies between related parameters, which is very useful for discovering potential security issues in function calls, such as whether function parameters are properly verified, whether there are unhandled exceptions or error conditions (function call parameters are not initialized or are other values ​​that may cause vulnerabilities). For arrays, data flow and control flow analysis can be used to track the value of the array index to determine whether the index is within the array size range to detect situations that may cause the array to go out of bounds. By tracking the data flow and control flow of pointers, it can help detect the pointer state (such as whether it is a null pointer) and the memory location pointed to by the pointer, and then detect pointer-related vulnerabilities such as null pointer dereference and pointer overflow. For arithmetic expressions, data flow and control flow analysis can identify situations in arithmetic expressions that may cause integer overflow or underflow by tracing the passing paths of the various variables involved in the arithmetic expression, and can detect situations that may cause division by zero errors in arithmetic expressions. It can also further understand the dependencies between variables and identify potential buffer overflow vulnerabilities. For example, if a variable in an arithmetic expression depends on another unchecked or unsafe variable, it may cause a buffer overflow vulnerability.

[0083] In this embodiment, understanding the data flow and control flow transfer path helps to discover possible vulnerabilities and attack surfaces. Therefore, by deeply analyzing the data flow and control flow of the target dangerous code, potential security vulnerabilities can be identified more accurately. Generating code slices can help locate the specific location of the target dangerous code in the program and the code snippets related to it.

[0084] In one embodiment, the process of constructing the positive prompt sample set and the negative prompt sample set includes:

[0085] Extracting a plurality of features of each first dangerous code slice and a plurality of features of each second dangerous code slice respectively;

[0086] Based on the clustering algorithm, clustering each first dangerous code slice according to multiple features of each first dangerous code slice to obtain multiple first cluster centers, and clustering each second dangerous code slice according to multiple features of each second dangerous code slice to obtain multiple second cluster centers;

[0087] Obtain the thought chain deduction process corresponding to each first cluster center, and the thought chain deduction process corresponding to each second cluster center, and use each first cluster center and the corresponding thought chain deduction process as a positive prompt sample set, and use each second cluster center and the corresponding thought chain deduction process as a negative prompt sample set.

[0088] Among them, features refer to the characteristics of each code slice, which may include code similarity measurement features, word frequency features TF-IDF, length features, and code features. Clustering algorithm is a machine learning method used to divide data samples into groups or clusters with similar features, which may include Kmeans clustering algorithm. Cluster center refers to the representative point or center in each cluster. It represents the average position of all samples in the cluster and is an important reference point. The cluster center obtained based on the clustering algorithm can help understand the characteristics and differences of each cluster, and then distinguish different types of code slices or samples.

[0089] Specifically, multiple first dangerous code slices and second dangerous code slices are extracted from the sample source code, and these slices contain dangerous code fragments. Determine the features suitable for describing the code slices, which may include code structure, keyword occurrence frequency, variable usage, etc. Use a clustering algorithm (such as K-means, hierarchical clustering, etc.) to cluster the first dangerous code slices and the second dangerous code slices. Based on the characteristics of each slice sample, they are divided into different clusters, and the center point of each cluster, i.e., the cluster center, is found. For each first cluster center and the second cluster center, a corresponding thinking chain deduction process is constructed, wherein the thinking chain deduction process can be a thinking path to guide developers to understand the code function or detect potential risks. Finally, each first cluster center and its corresponding thinking chain deduction process are used as a positive prompt sample set, and each second cluster center and its corresponding thinking chain deduction process are used as a negative prompt sample set.

[0090] In this embodiment, for different types of dangerous code slices, clustering is performed according to multiple features of the dangerous code, and cluster centers are selected as prompt samples, aiming to optimize the prompt sample selection and clustering method of the dangerous code slices, ensuring that the selected features can fully characterize the important information of the dangerous code slices, so that it can better capture the similarities and differences between dangerous codes, so as to improve the accuracy and efficiency of buffer overflow vulnerability detection. At the same time, this is for the effective use of computing resources and reducing dependence on human experts. Each cluster center corresponds to a thought chain deduction process, which can reduce the cost of constructing the prompt sample reasoning process. Constructing positive and negative prompt sample sets can provide a basis for further model training and security detection, wherein the positive prompt sample set can be used to train the model to identify similar dangerous code slices, while the negative prompt sample set can help eliminate false positives.

[0091] In one embodiment, the positive prompt sample set further includes the line number corresponding to each first dangerous code slice, the negative prompt sample set further includes the line number corresponding to each second dangerous code slice, and the method further includes:

[0092] Determine the line number corresponding to the code slice to be detected, and input the positive prompt sample set, the negative prompt sample set, the code slice to be detected and the line number corresponding to the code slice to be detected into the large language model to obtain the buffer overflow vulnerability detection result of the code slice to be detected.

[0093] The line number refers to the unique identifier of each line in the source code file, which is used to determine the code location.

[0094] Specifically, the specific location of each code slice in the source code file, i.e., the line number, can be determined by means such as static code analysis. For each code slice, the code slice to be detected can be determined according to specific detection rules and patterns, which may involve multiple lines of code or specific code snippets.

[0095] Furthermore, the code slice to be detected can be combined with its line number to generate a description of the detection problem, including but not limited to: dangerous code type, possible security risks, recommended repair methods, etc. Among them, the corresponding detection problem template can be designed according to the line number and the code slice to be detected, for example, does the [code slice to be detected] at [line number] cause a buffer overflow vulnerability? And the detection problem and the positive and negative prompt sample sets are input into the large language model.

[0096] In this embodiment, the code slice to be detected can be accurately located by using the code slice and its line number, so that the target large language model can understand the problem more clearly and accurately, thereby improving the accuracy and efficiency of code detection.

[0097] In one embodiment, the present application also provides a large language model training method, including:

[0098] S201: assigning a label value indicating the existence of a buffer overflow vulnerability to a positive prompt sample set, and assigning a label value indicating the absence of a buffer overflow vulnerability to a negative prompt sample set.

[0099] Among them, the positive prompt sample set is the positive prompt sample set in the buffer overflow vulnerability detection method of any of the above embodiments, and the negative prompt sample set is the negative prompt sample set in the buffer overflow vulnerability detection method of any of the above embodiments.

[0100] S202: Divide the positive prompt sample set into a first training subset and a first test subset, and divide the negative prompt sample set into a second training subset and a second test subset, and use the first training subset and the second training subset as training sets, and use the first test subset and the second test subset as test sets.

[0101] S203: Iteratively train the initial large language model using the training set and the test set, and obtain the large language model when the trained initial large language model meets a preset training end condition.

[0102] Specifically, first, a label value is assigned to each code snippet in the positive prompt sample set, such as "1", indicating that there is a buffer overflow vulnerability, and a label value is assigned to each code snippet in the negative prompt sample set, such as "0", indicating that there is no buffer overflow vulnerability. The positive prompt sample set is divided into a first training subset and a first test subset, and the negative prompt sample set is divided into a second training subset and a second test subset, and the first training subset and the second training subset are used as training sets, and the first test subset and the second test subset are used as test sets. For example, 80% of the samples can be used as training sets and 20% of the samples can be used as test sets. The initial large language model is iteratively trained using the training set. Specifically, a supervised learning method can be used, such as using a sample set with label values ​​for parameter update and model optimization, so that the model gradually learns the characteristics of the buffer overflow vulnerability in the code. After each round of iterative training, the model can be evaluated using the test set to understand the generalization ability and performance of the model. A preset training end condition is set, such as reaching a certain accuracy rate, loss function convergence, etc. When the model meets these conditions, the training can be considered to be completed. When the training is completed, an iteratively trained target large language model is obtained, which can more accurately identify buffer overflow vulnerabilities in the code.

[0103] In this embodiment, by assigning a buffer overflow label value to the positive prompt sample set, the model can better learn and understand the characteristics of the buffer overflow vulnerability, thereby having a higher accuracy in identifying such vulnerabilities. By assigning a buffer overflow label value to the negative prompt sample set, the model can learn the difference between the buffer overflow vulnerability and the normal code, thereby helping the model to better classify and identify. The target large language model obtained by iterative training and satisfying the end condition has better performance and accuracy, and can effectively identify the buffer overflow vulnerability.

[0104] The following is a description of the buffer overflow vulnerability detection device provided by the embodiment of the present application. The buffer overflow vulnerability detection device described below and the buffer overflow vulnerability detection method described above can be referred to each other. Figure 3 As shown, the present application provides a buffer overflow vulnerability detection device, the device comprising:

[0105] The target source code acquisition module 301 is used to acquire the target source code and extract each first dangerous code slice, each second dangerous code slice and a code slice to be detected from the target source code, wherein the first dangerous code slice is used to form a buffer overflow vulnerability, and the second dangerous code slice is used not to form a buffer overflow vulnerability;

[0106] The prompt sample set generation module 302 is used to generate a positive prompt sample set according to each first dangerous code slice and a preset first thought chain derivation process corresponding to each first dangerous code slice, and to generate a negative prompt sample set according to each second dangerous code slice and each preset second thought chain derivation process. The first thought chain derivation process is used to analyze whether the corresponding first dangerous code slice causes a buffer overflow vulnerability, and the second thought chain derivation process is used to analyze whether the corresponding second dangerous code slice does not form a buffer overflow vulnerability. The positive prompt sample set and the negative prompt sample set are used to prompt the large language model to perform a buffer overflow vulnerability detection task on the code slice to be detected;

[0107] The dangerous code detection module 303 is used to input the positive prompt sample set, the negative prompt sample set and the code slice to be detected into the large language model to obtain the buffer overflow vulnerability detection result of the code slice to be detected.

[0108] In one embodiment, the target source code acquisition module 301 includes:

[0109] A retrieval method determination submodule is used to determine a plurality of dangerous code types corresponding to the buffer overflow vulnerability code, and to determine a retrieval method corresponding to each dangerous code type;

[0110] A target dangerous code determination submodule is used to search the target source code using various search methods to determine the target dangerous code corresponding to each dangerous code type;

[0111] The dangerous code slice acquisition submodule is used to extract the first dangerous code and the second dangerous code from each target dangerous code through data flow analysis and control flow analysis, and to slice and extract each first dangerous code to obtain each first dangerous code slice, and to slice and extract each second dangerous code to obtain each second dangerous code slice.

[0112] In one embodiment, the dangerous code types include library / API function call types, array types, pointer types, and arithmetic expression types, and the retrieval method determination submodule includes:

[0113] A text template list determination unit, used to determine, for each hazard code type, a text template list corresponding to the hazard code type;

[0114] A first search mode determination unit is used to use a text matching mode as a search mode for library / API function call types and arithmetic expression types according to a text template list corresponding to library / API function call types and arithmetic expression types respectively;

[0115] The second search method determination unit is used to use the text matching method and the abstract syntax tree method as the search methods of the array type and the pointer type according to the text template list corresponding to the array type and the pointer type.

[0116] In one embodiment, the dangerous code slice acquisition submodule includes:

[0117] A data flow determination unit, used to determine the data flow and control flow of each first danger code, and to determine the data flow and control flow of each second danger code;

[0118] A code line extraction unit, used to extract the code line where the data flow and control flow of each first dangerous code are located, and to extract the code line where the data flow and control flow of each second dangerous code are located by using a graph traversal method;

[0119] The dangerous code slice acquisition unit is used to splice the code lines corresponding to each first dangerous code according to the program execution order in the target source code to obtain each first dangerous code slice, and to splice the code lines corresponding to each second dangerous code to obtain each second dangerous code slice.

[0120] In one embodiment, the prompt sample set generation module 302 includes:

[0121] A feature extraction submodule, used to extract multiple features of each first dangerous code slice and multiple features of each second dangerous code slice;

[0122] A clustering center submodule, for clustering each first dangerous code slice according to multiple features of each first dangerous code slice based on a clustering algorithm to obtain multiple first clustering centers, and clustering each second dangerous code slice according to multiple features of each second dangerous code slice to obtain multiple second clustering centers;

[0123] The sample set acquisition submodule is used to acquire the thought chain deduction process corresponding to each first cluster center and the thought chain deduction process corresponding to each second cluster center, and use each first cluster center and the corresponding thought chain deduction process as a positive prompt sample set, and use each second cluster center and the corresponding thought chain deduction process as a negative prompt sample set.

[0124] In one embodiment, the positive prompt sample set further includes the line number corresponding to each first dangerous code slice, the negative prompt sample set further includes the line number corresponding to each second dangerous code slice, and the device further includes:

[0125] The line number determination module is used to determine the line number corresponding to the code slice to be detected, and input the positive prompt sample set, the negative prompt sample set, the code slice to be detected and the line number corresponding to the code slice to be detected into the large language model to obtain the buffer overflow vulnerability detection result of the code slice to be detected.

[0126] In one embodiment, the present application further provides a large language model training device, comprising:

[0127] a label value assigning module, used to assign a label value indicating the existence of a buffer overflow vulnerability to a positive prompt sample set, and to assign a label value indicating the absence of a buffer overflow vulnerability to a negative prompt sample set, wherein the positive prompt sample set is a positive prompt sample set in the buffer overflow vulnerability detection method of any of the above embodiments, and the negative prompt sample set is a negative prompt sample set in the buffer overflow vulnerability detection method of any of the above embodiments;

[0128] A sample set division module, used to divide the positive prompt sample set into a first training subset and a first test subset, and divide the negative prompt sample set into a second training subset and a second test subset, and use the first training subset and the second training subset as training sets, and use the first test subset and the second test subset as test sets;

[0129] The large language model training module is used to iteratively train the initial large language model using a training set and a test set. When the trained initial large language model meets a preset training end condition, a large language model is obtained.

[0130] In one embodiment, the present application also provides a storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the buffer overflow vulnerability detection method described in any one of the above embodiments, and / or the steps of the large language model training method of the above embodiments.

[0131] In one embodiment, the present application also provides a computer device having computer-readable instructions stored therein. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the buffer overflow vulnerability detection method as described in any one of the above embodiments, and / or the steps of the large language model training method of the above embodiments.

[0132] Indicatively, if Figure 4 As shown, Figure 4 This is a schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. The computer device 400 may be provided as a server. Figure 4, the computer device 400 includes a processing component 402, which further includes one or more processors, and a memory resource represented by a memory 401, for storing instructions executable by the processing component 402, such as an application. The application stored in the memory 401 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 402 is configured to execute instructions to perform the buffer overflow vulnerability detection method of any of the above embodiments.

[0133] The computer device 400 may further include a power supply component 403 configured to perform power management of the computer device 400, a wired or wireless network interface 404 configured to connect the computer device 400 to a network, and an input / output (I / O) interface 405. The computer device 400 may operate based on an operating system stored in the memory 401, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, Free BSD TM, or the like.

[0134] Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0135] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the term "include", "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements not only includes those elements, but also includes other elements not clearly listed, or also includes elements inherent to such process, method, article or equipment. In the absence of more restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or equipment including the elements. Herein, "one", "one", "said", "the" and "it" may also include plural forms, unless the context clearly indicates another way. A plurality refers to at least two cases, such as 2, 3, 5 or 8, etc. "And / or" includes any and all combinations of the relevant listed items.

[0136] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can refer to each other.

[0137] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A buffer overflow vulnerability detection method, characterized in that: The method comprises: Obtaining a target source code, and extracting each first dangerous code slice, each second dangerous code slice, and a code slice to be detected from the target source code, wherein the first dangerous code slice is used to form a buffer overflow vulnerability, and the second dangerous code slice is used not to form a buffer overflow vulnerability; Generate a positive prompt sample set according to each of the first dangerous code slices and the preset first thought chain derivation process corresponding to each of the first dangerous code slices, and generate a negative prompt sample set according to each of the second dangerous code slices and each of the preset second thought chain derivation processes, the first thought chain derivation process is used to analyze whether the corresponding first dangerous code slice causes a buffer overflow vulnerability, and the second thought chain derivation process is used to analyze whether the corresponding second dangerous code slice does not form a buffer overflow vulnerability, and the positive prompt sample set and the negative prompt sample set are used to prompt the large language model to perform a buffer overflow vulnerability detection task on the code slice to be detected; The positive prompt sample set, the negative prompt sample set and the code slice to be detected are input into the large language model to obtain a buffer overflow vulnerability detection result of the code slice to be detected.

2. The buffer overflow vulnerability detection method according to claim 1, characterized in that: The step of extracting each first dangerous code slice and each second dangerous code slice from the target source code comprises: Determine a plurality of dangerous code types corresponding to the buffer overflow vulnerability code, and determine a retrieval method corresponding to each of the dangerous code types; Using each of the retrieval methods to search the target source code to determine the target dangerous code corresponding to each of the dangerous code types; Through data flow analysis and control flow analysis, the first danger code and the second danger code are extracted from each of the target danger codes, and each of the first danger codes is sliced ​​and extracted to obtain each of the first danger code slices, and each of the second danger codes is sliced ​​and extracted to obtain each of the second danger code slices.

3. The buffer overflow vulnerability detection method according to claim 2, characterized in that: The dangerous code types include library / API function call types, array types, pointer types, and arithmetic expression types. The step of determining the retrieval method corresponding to each of the dangerous code types includes: For each of the hazard code types, determining a text template list corresponding to the hazard code type; According to the text template lists corresponding to the library / API function call type and the arithmetic expression type, a text matching method is used as a search method for the library / API function call type and the arithmetic expression type; According to the text template list corresponding to the array type and the pointer type, a text matching method and an abstract syntax tree method are used as retrieval methods for the array type and the pointer type.

4. The buffer overflow vulnerability detection method according to claim 2, characterized in that: The steps of slicing and extracting each of the first danger codes to obtain each of the first danger code slices, and slicing and extracting each of the second danger codes to obtain each of the second danger code slices, include: Determine the data flow and control flow of each of the first hazard codes, and determine the data flow and control flow of each of the second hazard codes; Extracting the code line where the data flow and control flow of each first dangerous code are located by using a graph traversal method, and extracting the code line where the data flow and control flow of each second dangerous code are located; The code lines corresponding to each of the first dangerous codes are spliced ​​according to the program execution order in the target source code to obtain each of the first dangerous code slices, and the code lines corresponding to each of the second dangerous codes are spliced ​​to obtain each of the second dangerous code slices.

5. The buffer overflow vulnerability detection method according to claim 1, characterized in that: The process of constructing the positive prompt sample set and the negative prompt sample set includes: Respectively extracting a plurality of features of each of the first dangerous code slices and a plurality of features of each of the second dangerous code slices; Based on a clustering algorithm, clustering each of the first dangerous code slices according to multiple features of each of the first dangerous code slices to obtain multiple first cluster centers, and clustering each of the second dangerous code slices according to multiple features of each of the second dangerous code slices to obtain multiple second cluster centers; Obtain the first thought chain deduction process corresponding to each of the first cluster centers, and the second thought chain deduction process corresponding to each of the second cluster centers, and use each of the first cluster centers and the corresponding thought chain deduction process as the positive prompt sample set, and use each of the second cluster centers and the corresponding thought chain deduction process as the negative prompt sample set.

6. The buffer overflow vulnerability detection method according to any one of claims 1 to 5, characterized in that: The positive prompt sample set further includes a line number corresponding to each of the first dangerous code slices, and the negative prompt sample set further includes a line number corresponding to each of the second dangerous code slices. The method further includes: Determine the line number corresponding to the code slice to be detected, and input the positive prompt sample set, the negative prompt sample set, the code slice to be detected and the line number corresponding to the code slice to be detected into the large language model to obtain a buffer overflow vulnerability detection result of the code slice to be detected.

7. A large language model training method, characterized in that: include: Assigning a label value for indicating the existence of a buffer overflow vulnerability to a positive prompt sample set, and assigning a label value for indicating the absence of a buffer overflow vulnerability to a negative prompt sample set, wherein the positive prompt sample set is the positive prompt sample set in the buffer overflow vulnerability detection method according to any one of claims 1 to 6, and the negative prompt sample set is the negative prompt sample set in the buffer overflow vulnerability detection method according to any one of claims 1 to 6; Dividing the positive prompt sample set into a first training subset and a first test subset, and dividing the negative prompt sample set into a second training subset and a second test subset, and using the first training subset and the second training subset as training sets, and using the first test subset and the second test subset as test sets; The training set and the test set are used to iteratively train the initial large language model, and when the trained initial large language model meets a preset training end condition, a large language model is obtained.

8. A buffer overflow vulnerability detection device, characterized in that: The device comprises: A target source code acquisition module, used to acquire the target source code, and extract each first dangerous code slice, each second dangerous code slice and a code slice to be detected from the target source code, wherein the first dangerous code slice is used to form a buffer overflow vulnerability, and the second dangerous code slice is used not to form a buffer overflow vulnerability; A prompt sample set generation module is used to generate a positive prompt sample set according to each of the first dangerous code slices and the preset first thought chain deduction process corresponding to each of the first dangerous code slices, and to generate a negative prompt sample set according to each of the second dangerous code slices and each of the preset second thought chain deduction processes, wherein the first thought chain deduction process is used to analyze whether the corresponding first dangerous code slice causes a buffer overflow vulnerability, and the second thought chain deduction process is used to analyze whether the corresponding second dangerous code slice does not form a buffer overflow vulnerability, and the positive prompt sample set and the negative prompt sample set are used to prompt the large language model to perform a buffer overflow vulnerability detection task on the code slice to be detected; The dangerous code detection module is used to input the positive prompt sample set, the negative prompt sample set and the code slice to be detected into the large language model to obtain a buffer overflow vulnerability detection result of the code slice to be detected.

9. A storage medium, characterized in that: The storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors execute the buffer overflow vulnerability detection method as described in any one of claims 1 to 6, and / or execute the steps of the large language model training method as described in claim 7.

10. A computer device, characterized in that: include: one or more processors, and memory; The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the buffer overflow vulnerability detection method as described in any one of claims 1 to 6 is executed, and / or the steps of the large language model training method as described in claim 7 are executed.

Citation Information

Cited By

  • Code vulnerability detection method and device, computer equipment, storage medium and product

    CN121435244A