Memory-based program source code test method and device, equipment and medium
By extracting the control flowchart and function call diagram of the program source code, filtering dangerous operation sequences and monitoring memory consumption and coverage, the limitations of memory security vulnerability detection in the existing technology are solved, and comprehensive detection of memory security vulnerabilities is achieved.
Patent Information
- Application Number
- CN202411228787.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2044-09-03
AI Technical Summary
In the prior art, program source code testing methods can only test some memory security vulnerabilities, which have limitations.
By extracting the control flowchart and function call diagram of the program source code, filter out dangerous operation sequences related to memory vulnerabilities, monitor memory consumption, code coverage and dangerous operation coverage, update test cases until the program source code crashes, and determine memory security Vulnerability type.
It realizes comprehensive monitoring and detection of memory security vulnerabilities, which can more accurately identify whether the program operation meets the memory usage protocol, thereby more comprehensively testing of memory security vulnerabilities caused by running the program source code.
Smart Images

Figure CN119088710A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of program testing technology, and in particular to a memory-based program source code testing method, device, equipment and medium. Background Art
[0002] Running program source code on a computer will have a certain impact on memory, and memory security vulnerabilities are used to characterize this impact. The existing technology uses memory space fuzz testing methods and memory timing fuzz testing methods to test the types of memory security vulnerabilities caused by running program source code. Both of the above fuzz testing methods can only test some types of memory security vulnerabilities.
[0003] In summary, the types of memory security vulnerabilities tested by program source code testing methods in the prior art have limitations.
[0004] Therefore, the prior art still needs to be improved and enhanced. Summary of the invention
[0005] To solve the above technical problems, the present invention provides a memory-based program source code testing method, device, equipment and medium, which solves the problem that the types of memory security vulnerabilities tested by the program source code testing method in the prior art are limited.
[0006] To achieve the above object, the present invention adopts the following technical solutions:
[0007] In a first aspect, the present invention provides a memory-based program source code testing method, which includes:
[0008] Extracting a control flow graph and a function call graph from a program source code, extracting memory operations required when running the program source code, and screening out dangerous operation sequences related to memory vulnerabilities from all operation sequences involved in the memory operations;
[0009] Input the test case into the program source code, and when the program source code after the test case is input does not crash, monitor the memory consumption, code coverage, and dangerous operation coverage, wherein the memory consumption is the memory consumed by the program source code after the test case is input when executing the control flow graph, the function call graph, and the memory operation; the code coverage is used to characterize the proportion of the executed code in the program source code, and the dangerous operation coverage is used to characterize the degree to which the dangerous operation sequence is executed;
[0010] The test case is updated according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes, and a target test case is obtained. The target test case is used to determine the memory security vulnerability type of the program source code.
[0011] In one implementation, the step of screening out dangerous operation sequences related to memory vulnerabilities from all operation sequences involved in the memory operation includes:
[0012] determining a timing protocol rule violation in the memory vulnerability;
[0013] Determining an operation sequence consisting of the memory operations;
[0014] The dangerous operation sequences that violate the timing protocol rules are screened out from all the operation sequences.
[0015] In one implementation, the step of screening out the dangerous operation sequence that violates the timing protocol rule from all the operation sequences includes:
[0016] Determining a double free vulnerability or a use-after-free vulnerability in said violation of the timing protocol rule;
[0017] The dangerous operation sequences constituting the double-free vulnerability or the use-after-free vulnerability are screened out from all the operation sequences.
[0018] In one implementation, monitoring memory consumption, code coverage, and dangerous operation coverage includes:
[0019] Inserting a monitoring program into the program source code;
[0020] The memory consumption, the code coverage, and the dangerous operation coverage are monitored through the monitoring program.
[0021] In one implementation, monitoring the memory consumption, the code coverage, and the dangerous operation coverage by the monitoring program includes:
[0022] Counting the memory allocation operations and memory release operations corresponding to the control flow graph, the function call graph, and the memory operations;
[0023] The memory consumed by each memory allocation operation is monitored by the monitoring program, and recorded as allocation consumption;
[0024] The memory consumed by each memory release operation is monitored by the monitoring program, and recorded as release consumption;
[0025] Obtaining memory consumption according to the allocation consumption and the release consumption;
[0026] Monitor each code in the program source code by the monitoring program to obtain the executed code;
[0027] Determine the percentage of code that has been executed and use that percentage as code coverage;
[0028] The monitoring program is used to monitor the positions of the release operation and the allocation operation in the dangerous operation sequence, and the executed dangerous operation sequence is selected from the dangerous operation sequence according to the positions;
[0029] The dangerous operation coverage rate is obtained according to the number of the dangerous operation sequences and the number of the executed dangerous operation sequences.
[0030] In one implementation, updating the test case according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes to obtain a target test case includes:
[0031] When the code coverage changes, the memory consumption changes, or the dangerous operation coverage changes, determining a test variation case of the test case;
[0032] The test variation case is input into the program source code, and when the program source code does not crash after the test variation case is input, the test case is updated until the program source code crashes, thereby obtaining a target test case.
[0033] In one implementation, the updating of the test case according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes to obtain a target test case further includes:
[0034] When the program source code crashes after the test mutation case is input, the test mutation case is used as a target test case.
[0035] In a second aspect, an embodiment of the present invention further provides a memory-based program source code testing device, wherein the device includes the following components:
[0036] An information extraction module is used to extract a control flow graph and a function call graph from a program source code, extract memory operations required when running the program source code, and screen out dangerous operation sequences related to memory vulnerabilities from all operation sequences involved in the memory operations;
[0037] A monitoring module, used for inputting a test case into the program source code, and monitoring memory consumption, code coverage, and dangerous operation coverage when the program source code after the test case is input does not crash, wherein the memory consumption is the memory consumed by the program source code after the test case is input when executing the control flow graph, the function call graph, and the memory operation; the code coverage is used to characterize the proportion of the executed code in the program source code, and the dangerous operation coverage is used to characterize the degree to which the dangerous operation sequence is executed;
[0038] An update module is used to update the test case according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes, thereby obtaining a target test case, wherein the target test case is used to determine the memory security vulnerability type of the program source code.
[0039] In a third aspect, an embodiment of the present invention further provides a terminal device, wherein the terminal device includes a memory, a processor, and a memory-based program source code test program stored in the memory and executable on the processor, and when the processor executes the memory-based program source code test program, the steps of the above-mentioned memory-based program source code testing method are implemented.
[0040] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a memory-based program source code test program is stored. When the memory-based program source code test program is executed by a processor, the steps of the above-mentioned memory-based program source code test method are implemented.
[0041] Beneficial effects: The present invention first analyzes the control flow graph, function call graph and memory operations contained in the program source code, and screens out dangerous operation sequences from the memory operations, then inputs the test case into the program source code, and then starts to monitor the memory consumed by the program source code to complete the control flow graph, function call graph and memory operations, and after the program source code is run, monitors the code that has been run in the program source code to obtain the code coverage, and also monitors the code that has been run in the dangerous operation sequence to obtain the dangerous operation coverage. Finally, according to the code coverage, memory consumption, and dangerous operation coverage, the test case is updated until the program source code crashes, and the target test case is obtained. According to the target test case, the type of memory security vulnerability caused by running the program source code can be analyzed. From the above analysis, it can be seen that the present invention not only monitors memory consumption but also monitors code coverage and dangerous operation coverage, so that the present invention can more comprehensively monitor whether the operation of the program source code meets the memory usage protocol, so as to more comprehensively test the type of memory security vulnerability caused by running the program source code. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 It is the overall flow chart of the present invention;
[0043] Figure 2 A flowchart of static analysis and fuzz testing in an embodiment of the present invention;
[0044] Figure 3 A memory usage protocol diagram in an embodiment of the present invention;
[0045] Figure 4 A structural diagram of a program source code testing device based on memory provided by the present invention;
[0046] Figure 5 This is a block diagram of the internal structure principle of the terminal device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0047] The following is a clear and complete description of the technical solution of the present invention in combination with the embodiments and the accompanying drawings. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0048] Research has found that running program source code on a computer will have a certain impact on memory, and memory security vulnerabilities are used to characterize this impact. The existing technology uses memory space fuzz testing methods and memory timing fuzz testing methods to test the types of memory security vulnerabilities caused by running program source code. Both of the above fuzz testing methods can only test some types of memory security vulnerabilities.
[0049] In order to solve the above technical problems, the types of memory security vulnerabilities tested by the program source code testing method in the prior art have limitations. In specific implementation, the control flow graph and function call graph of the program source code are first extracted, the memory operations required when running the program source code are extracted, and the dangerous operation sequences related to memory vulnerabilities are screened out from the memory operations; then the test case is input into the program source code, and when the program source code after the test case is input does not crash, the memory consumption, code coverage, and dangerous operation coverage are monitored, wherein the memory consumption is the memory consumed by the program source code after the test case is input when executing the control flow graph, function call graph, and memory operations; the code coverage is used to characterize the proportion of the running code in the program source code, and the dangerous operation coverage is used to characterize the degree to which the dangerous operation sequence is run; finally, based on the code coverage, memory consumption, and dangerous operation coverage, the test case is updated until the program source code crashes, and the target test case is obtained, and the target test case is used to determine the type of memory security vulnerability in the program source code.
[0050] For example, the control flow graph and function call graph of the program source code are extracted, and the memory operations required when running the program source code are extracted. The control flow graph is used to characterize the steps and the order of executing the steps that the program source code needs to perform in order to realize its functions, that is, the control flow graph is used to collect branch coverage. The function call graph is used to characterize the functions that need to be called to run the program source code, that is, the function call graph is used to record the entries and returns of function calls. Memory operations are the memory operations that need to be performed to run the program source code on a computer. For example, memory operations include memory operations a, memory operations b, memory operations c, memory operations d, memory operations e, and memory operations f. Executing these six memory operations in different execution orders will produce different operation sequences, among which the operation sequence: b, d, c will cause memory vulnerabilities, that is, executing memory operations b, memory operations d, and memory operations c in sequence will cause memory vulnerabilities, then the operation sequence: b, d, c is a dangerous operation sequence. Similarly, if the operation sequence c, e, b will also cause memory vulnerabilities, then the operation sequence c, e, b is also a dangerous operation sequence.
[0051] Input test case A into the program source code. If the program source code does not crash at this time, monitor the control flow graph, function call graph and memory consumed by memory operations during the execution of the program source code, that is, monitor memory consumption. Also monitor the code that needs to be executed in the program source code to output the result corresponding to the test case. The ratio of this code to all the codes in the program source code is the code coverage. Monitor which of the first dangerous operation sequence: b, d, c and the second dangerous operation sequence: c, e, b are executed to obtain the dangerous operation coverage.
[0052] According to the code coverage, memory consumption, and dangerous operation coverage, test case A is updated until the program source code crashes. The test case at the time of the crash is the target test case. The updated test case A can be a test variant case that generates test case A (which is the existing technology), or it can be another test case B that replaces test case A.
[0053] Test case A is input into the program source code. If the program source code has crashed at this time, then test case A is used as the target test case. The type of memory safety vulnerability caused by the program source code is determined based on the target test case, where the type of memory safety vulnerability is confirmed to be prior art.
[0054] The program source code testing method of this embodiment can be applied to a terminal device, which can be a terminal product with a data processing function, such as a computer. Figure 1 As shown in , the program source code testing method specifically includes the following steps:
[0055] S100, extracting a control flow graph and a function call graph from a program source code, extracting memory operations required when running the program source code, and screening out dangerous operation sequences related to memory vulnerabilities from all operation sequences involved in the memory operations;
[0056] S200, inputting a test case into the program source code, and when the program source code after the test case is input does not crash, monitoring memory consumption, code coverage, and dangerous operation coverage, wherein the memory consumption is the memory consumed by the program source code after the test case is input when executing the control flow graph, the function call graph, and the memory operation; the code coverage is used to characterize the proportion of the executed code in the program source code, and the dangerous operation coverage is used to characterize the degree to which the dangerous operation sequence is executed;
[0057] S300, updating the test case according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes, and obtaining a target test case, wherein the target test case is used to determine the memory security vulnerability type of the program source code.
[0058] Extract the control flow graph, function call graph, memory operations involved in the program source code, and filter out memory sequences (memory sequences are also dangerous operation sequences) from the memory operations. Insert a monitoring program into the extracted program source code to monitor the control flow graph, function call graph, memory operations, and dangerous operation sequences. Figure 2 As shown in the figure, the control flow graph, function call graph, memory operation and dangerous operation sequence are extracted to output the static analysis content. The test case is input into the program source code, and the code coverage, memory consumption and dangerous operation coverage (dangerous operation coverage is also called Figure 2 ), if the values of code coverage, memory consumption and dangerous operation coverage reach the point where the program source code crashes, then the test case is used as the target test case. If the program source code does not crash, but the values of code coverage, memory consumption and dangerous operation coverage have changed, then the test case is put into the seed pool to update the seed pool (the seed pool is used to provide test cases for testing other program source codes). Generate several test mutation cases of the test case (the number of test mutation cases is recorded as energy value), and input several test mutation cases into the program source code one by one to determine whether the program source code crashes by monitoring the code coverage, memory consumption and dangerous operation coverage at this time. If it crashes, the test mutation case corresponding to the crash is used as the target test case.
[0059] The program source code testing method of the present application also includes testing memory use-after-free vulnerability (UAF vulnerability) and double free vulnerability (DF vulnerability). The specific testing process is as follows:
[0060] When the memory operation is allocated for memory (the memory size is denoted as m), such as Figure 3 As shown, first check whether the current memory consumption M plus m exceeds the preset memory threshold (i.e., the system memory size), that is, whether M+m is greater than the preset memory threshold. If it exceeds the threshold, it means that the memory operation will cause a memory overflow vulnerability or a memory allocation failure vulnerability. Otherwise, update the current memory consumption to M+m, that is, M=M+m, and allocate a memory block for the memory operation, and set the allocation status of the memory block (that is, the memory block has been allocated to the memory operation for use).
[0061] The memory block is in an allocated state, that is, the memory block remains active until the memory block is released or the program source code exits, then it can be analyzed that the program source code has a vulnerability that can cause memory leakage.
[0062] When the memory block is released, it enters the recycling state and updates the current memory consumption to Mm, that is, M = Mm. If any use or release operation is performed on the memory block after release, the state of the memory block is a trap state, which means that the program source code has two vulnerabilities: test memory use after release and double release.
[0063] Any use or free operation on an uninitialized memory address (in the init state) indicates a NULL pointer dereference vulnerability or invalid free vulnerability has been detected.
[0064] You can also use a global variable D to indicate the current stack depth. When a function is called, the variable D+1; when the function returns, D-1. It is worth noting that recursive functions may be called excessively, gradually consuming the stack until it overflows.
[0065] The depth of the stack represents the degree of memory space vulnerability. Memory space vulnerability refers to dangerous memory operations. Once the memory operation is executed, it will cause the system resources to be occupied beyond the threshold. For example, after entering the function, the stack exceeds the depth of the system stack, or the memory allocation exceeds the allocatable space size.
[0066] Embodiment 1: This embodiment first selects operation sequences with a length greater than 1 from the operation sequences corresponding to the memory operations. This is because operation sequences with a length greater than 1 are likely to cause the memory block to be in a trap state (i.e., violate the protocol timing rules). The operation sequence that can cause the memory block to be in a defective state is a dangerous operation sequence. This embodiment selects dangerous operation sequences including the following specific steps: determining the violation of the timing protocol rules in the memory vulnerability; determining the operation sequence constituted by the memory operation; determining the double free vulnerability or the use-after-free vulnerability in the violation of the timing protocol rules; and selecting the dangerous operation sequence that constitutes the double free vulnerability or the use-after-free vulnerability from all the operation sequences.
[0067] This embodiment screens dangerous operation sequences based on the following principle: first, all memory allocation operations and pointers to their corresponding allocated memory objects are collected, and the results are stored in S M (Line 2), for each memory operation s m and its corresponding object m, using pointer analysis to identify their potential alias pointers (line 4). MemSpate then identifies all memory release operations that release memory object m through alias pointers and generates a set S F (Line 5).
[0068] Find all memory usage operations associated with any alias pointer m and generate a set S U (Line 6).
[0069] With the help of reachability analysis, if s m Can reach S F , S F , then the operation sequence [s m ,s f ,s u ]; if s m Can reach S F , S F Can reach s' f , then add the operation sequence [s m ,s f , s' f ], where s u It is the usage operation from SU, f and s' f It is from S F Two different release operations, namely [s m ,s f ,s u ] is a use-after-free vulnerability, [s m ,s f , s' f ] is a double release vulnerability.
[0070] In this embodiment, the algorithm required to screen the two dangerous operation sequences of double free vulnerability and use-after-free vulnerability is as follows:
[0071]
[0072] Embodiment 2, based on embodiment 1, monitoring memory consumption, code coverage, and dangerous operation coverage in step S200 of this embodiment includes the following specific steps S201 to S209:
[0073] S201, inserting a monitoring program into the program source code.
[0074] S202, counting the memory allocation operations and memory release operations corresponding to the control flow graph, the function call graph, and the memory operations.
[0075] S203, monitoring the memory consumed by each memory allocation operation through the monitoring program, and recording it as allocation consumption.
[0076] For allocation operations, it is necessary to calculate the size of each allocated memory and add up the memory sizes to get the memory size consumed by the allocation operation. That is, the allocation consumption is counted from lines 9 to 11 of the algorithm.
[0077] S204, monitoring the memory consumed by each memory release operation through the monitoring program, and recording it as release consumption.
[0078] For each release operation, we need to find the size of the memory released and add up the memory size to get the memory size consumed by the release operation. That is, we count the release consumption from lines 13 to 15 of the algorithm.
[0079] S205: Obtain memory consumption according to the allocation consumption and the release consumption.
[0080] This embodiment uses the allocation consumption and the release consumption as the memory size consumed by the allocation operation and the release operation.
[0081] This embodiment also records the entry (line 3) and return instructions (line 7) of each function, and increases (line 4) and decreases (line 9) the stack depth by 1 accordingly. At the same time, MemSpate tracks the maximum stack depth (line 5), which is beneficial for seed selection during the fuzzy loop. And tracks the maximum memory consumption (line 12), which is also beneficial for seed selection during the fuzzy loop.
[0082] S206, monitoring each code in the program source code through the monitoring program to obtain the executed code.
[0083] Use code_cov to detect each basic block in the program source code to determine whether the code in each basic block has been executed, that is, to detect the executed code through line 26 of the algorithm.
[0084] S207, determining the percentage of executed code, and using the percentage as code coverage;
[0085] S208, monitoring the positions of the release operation and the allocation operation in the dangerous operation sequence through the monitoring program, and filtering out the executed dangerous operation sequence from the dangerous operation sequence according to the positions.
[0086] S209: Obtain a dangerous operation coverage rate according to the number of dangerous operation sequences and the number of executed dangerous operation sequences.
[0087] Steps S208 and S209 are to detect which operation sequences in the dangerous operation sequence have been executed, that is, if the instructions of the program source code contain a release operation (line 16 of the algorithm), then all sequences related to the release are retrieved (line 17). For each sequence seq, if the release appears at the last position in seq (that is, the sequence is a DF sequence), it means that the sequence is covered (lines 18-19), that is, it has been executed; otherwise (that is, a subsequence of a UAF or DF sequence), MemSpate locates the position of the release in seq and marks the position as covered (lines 21-22). For the allocation operation Use operation, follow a similar procedure, that is, through lines 23-25 of the algorithm to detect whether the allocation operation appears at the last position of the sequence to detect whether the sequence has been executed.
[0088] This embodiment detects whether a sequence has been executed, that is, whether it has been overwritten, by the following algorithm:
[0089]
[0090] Embodiment 3, this example comprises the following specific steps:
[0091] When the code coverage changes, the memory consumption changes, or the dangerous operation coverage changes, determining a test variation case of the test case;
[0092] The test variation case is input into the program source code, and when the program source code does not crash after the test variation case is input, the test case is updated until the program source code crashes, thereby obtaining a target test case.
[0093] When the program source code crashes after the test mutation case is input, the test mutation case is used as a target test case.
[0094] First, initialize the seeds in the seed pool (the seeds are also test cases) (corresponding to line 3 of the algorithm), then select a seed from the seed pool Queue (corresponding to line 5 of the algorithm), and set an energy value testcase_num for the seed (corresponding to line 6 of the algorithm, setting the energy value is to set the number of test mutation cases for the test case, where the test mutation case generated by the test case is the prior art). Afterwards, for each mutated test case (that is, test mutation case), monitor the execution of the detection program P' (that is, the program source code) and collect information about code coverage, memory operation sequence coverage, maximum stack depth, and maximum memory consumption (corresponding to line 9 of the algorithm). If the program crashes, then tasecase will be added to the crash set S (corresponding to lines 10-11 of the algorithm). In addition, if this crash is classified as a memory-related vulnerability by ASAN, this seed will be added to S mem (Corresponding to lines 12-13 of the algorithm). Otherwise, check whether the test case increases the coverage of new code branches (corresponding to line 14 of the algorithm), introduces new memory operation sequence coverage (corresponding to line 16 of the algorithm), or causes greater stack / heap memory consumption (corresponding to line 18 of the algorithm), then the test case will be added to the seed pool for further testing (lines 15, 17, and 19).
[0095]
[0096]
[0097] In summary, the test method of the present invention uses a more comprehensive memory usage protocol to identify memory operation sequences that may violate the protocol and estimate whether the running memory consumption exceeds an acceptable threshold. The coverage of these operation sequences is then monitored and the maximum memory consumption is tracked. The test method of the present invention fully considers the detection of memory space vulnerabilities and memory timing vulnerabilities, and can test for stack overflow, heap overflow, allocation failure, double-free, heap-use-after-free, invalid-free and null-pointer-dereference.
[0098] This embodiment also provides a memory-based program source code testing device, such as Figure 4 As shown, the device comprises the following components:
[0099] The information extraction module 01 is used to extract the control flow graph and function call graph of the program source code, extract the memory operations required when running the program source code, and screen out the dangerous operation sequences related to the memory vulnerability from all the operation sequences involved in the memory operations;
[0100] Monitoring module 02, used for inputting test cases into the program source code, and monitoring memory consumption, code coverage, and dangerous operation coverage when the program source code after the test cases are input does not crash, wherein the memory consumption is the memory consumed by the program source code after the test cases are input when executing the control flow graph, the function call graph, and the memory operation; the code coverage is used to characterize the proportion of the executed code in the program source code, and the dangerous operation coverage is used to characterize the degree to which the dangerous operation sequence is executed;
[0101] Update module 03 is used to update the test case according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes, and obtain the target test case, which is used to determine the memory security vulnerability type of the program source code.
[0102] Based on the above embodiments, the present invention further provides a terminal device, whose principle block diagram can be shown as follows: Figure 5 As shown. The terminal device includes a processor, a memory, a network interface, and a display screen connected through a system bus. Among them, the processor of the terminal device is used to provide computing and control capabilities. The memory of the terminal device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the terminal device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a memory-based program source code testing method is implemented. The display screen of the terminal device can be a liquid crystal display screen or an electronic ink display screen.
[0103] Those skilled in the art will understand that Figure 5 The principle block diagram shown in the figure is only a block diagram of a partial structure related to the scheme of the present invention, and does not constitute a limitation on the terminal device to which the scheme of the present invention is applied. The specific terminal device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0104] In one embodiment, a terminal device is provided, the terminal device comprising a memory, a processor, and a memory-based program source code test program stored in the memory and executable on the processor, and when the processor executes the memory-based program source code test program, the following operation instructions are implemented:
[0105] Extracting a control flow graph and a function call graph from a program source code, extracting memory operations required when running the program source code, and screening out dangerous operation sequences related to memory vulnerabilities from all operation sequences involved in the memory operations;
[0106] Input the test case into the program source code, and when the program source code after the test case is input does not crash, monitor the memory consumption, code coverage, and dangerous operation coverage, wherein the memory consumption is the memory consumed by the program source code after the test case is input when executing the control flow graph, the function call graph, and the memory operation; the code coverage is used to characterize the proportion of the executed code in the program source code, and the dangerous operation coverage is used to characterize the degree to which the dangerous operation sequence is executed;
[0107] The test case is updated according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes, and a target test case is obtained. The target test case is used to determine the memory security vulnerability type of the program source code.
[0108] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0109] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A memory-based program source code testing method, characterized in that: include: Extracting a control flow graph and a function call graph from a program source code, extracting memory operations required when running the program source code, and screening out dangerous operation sequences related to memory vulnerabilities from all operation sequences involved in the memory operations; Input the test case into the program source code, and when the program source code after the test case is input does not crash, monitor the memory consumption, code coverage, and dangerous operation coverage, wherein the memory consumption is the memory consumed by the program source code after the test case is input when executing the control flow graph, the function call graph, and the memory operation; the code coverage is used to characterize the proportion of the executed code in the program source code, and the dangerous operation coverage is used to characterize the degree to which the dangerous operation sequence is executed; The test case is updated according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes, and a target test case is obtained. The target test case is used to determine the memory security vulnerability type of the program source code.
2. The memory-based program source code testing method according to claim 1, characterized in that: The step of screening out dangerous operation sequences related to memory vulnerabilities from all operation sequences involved in the memory operation includes: determining a timing protocol rule violation in the memory vulnerability; Determining an operation sequence consisting of the memory operations; The dangerous operation sequences that violate the timing protocol rules are screened out from all the operation sequences.
3. The memory-based program source code testing method according to claim 2, characterized in that: The step of screening out the dangerous operation sequence that violates the timing protocol rule from all the operation sequences comprises: Determining a double free vulnerability or a use-after-free vulnerability in said violation of the timing protocol rule; The dangerous operation sequences constituting the double-free vulnerability or the use-after-free vulnerability are screened out from all the operation sequences.
4. The memory-based program source code testing method according to claim 1, characterized in that: The monitoring of memory consumption, code coverage, and dangerous operation coverage includes: Inserting a monitoring program into the program source code; The memory consumption, the code coverage, and the dangerous operation coverage are monitored through the monitoring program.
5. The memory-based program source code testing method according to claim 4, characterized in that: The monitoring of the memory consumption, the code coverage, and the dangerous operation coverage by the monitoring program includes: Counting the memory allocation operations and memory release operations corresponding to the control flow graph, the function call graph, and the memory operations; The memory consumed by each memory allocation operation is monitored by the monitoring program, and recorded as allocation consumption; The memory consumed by each memory release operation is monitored by the monitoring program, and recorded as release consumption; Obtaining memory consumption according to the allocation consumption and the release consumption; Monitor each code in the program source code by the monitoring program to obtain the executed code; Determine the percentage of code that has been executed and use that percentage as code coverage; The monitoring program is used to monitor the positions of the release operation and the allocation operation in the dangerous operation sequence, and the executed dangerous operation sequence is selected from the dangerous operation sequence according to the positions; The dangerous operation coverage rate is obtained according to the number of the dangerous operation sequences and the number of the executed dangerous operation sequences.
6. The memory-based program source code testing method according to claim 1, characterized in that: The updating of the test case according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes to obtain a target test case includes: When the code coverage changes, the memory consumption changes, or the dangerous operation coverage changes, determining a test variation case of the test case; The test variation case is input into the program source code, and when the program source code does not crash after the test variation case is input, the test case is updated until the program source code crashes, thereby obtaining a target test case.
7. The memory-based program source code testing method according to claim 6, characterized in that: The method of updating the test case according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes to obtain a target test case further includes: When the program source code crashes after the test mutation case is input, the test mutation case is used as a target test case.
8. A memory-based program source code testing device, characterized in that: The device comprises the following components: An information extraction module is used to extract a control flow graph and a function call graph from a program source code, extract memory operations required when running the program source code, and screen out dangerous operation sequences related to memory vulnerabilities from all operation sequences involved in the memory operations; A monitoring module, used for inputting a test case into the program source code, and monitoring memory consumption, code coverage, and dangerous operation coverage when the program source code after the test case is input does not crash, wherein the memory consumption is the memory consumed by the program source code after the test case is input when executing the control flow graph, the function call graph, and the memory operation; the code coverage is used to characterize the proportion of the executed code in the program source code, and the dangerous operation coverage is used to characterize the degree to which the dangerous operation sequence is executed; An update module is used to update the test case according to the code coverage, the memory consumption, and the dangerous operation coverage until the program source code crashes, thereby obtaining a target test case, wherein the target test case is used to determine the memory security vulnerability type of the program source code.
9. A terminal device, characterized in that: The terminal device includes a memory, a processor, and a memory-based program source code test program stored in the memory and executable on the processor. When the processor executes the memory-based program source code test program, the steps of the memory-based program source code test method as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a memory-based program source code test program, and when the memory-based program source code test program is executed by a processor, the steps of the memory-based program source code test method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Guiding type grey box fuzzy testing method and device based on dominating point coverage
CN114661578A
Internet of Things terminal security vulnerability detection system and method based on heap management mechanism
CN117521085A
Automatic memory leak vulnerability mining method based on risk code area
CN117851250A
Intelligent contract vulnerability detection method based on combination of static analysis and fuzzy testing
CN117951712A
