Code detection method, device and equipment, computer readable storage medium and computer program product
By decomposing the array subscripts in static code and comparing the judgment statements, the problem of difficulty in obtaining array subscript ranges in the existing technology is solved, and the efficiency and accuracy of code detection are improved.
Patent Information
- Application Number
- CN202410088927.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-22
- Publication Date
- 2025-07-22
AI Technical Summary
In the prior art, in code detection, especially static code detection, there are difficulties in obtaining array subscript ranges and inaccurate results, resulting in missed or false positives, making it difficult to improve detection efficiency and accuracy.
By decomposing the array subscripts in the static code, multiple decomposition subscripts are obtained, and based on the judgment conditions of the judgment position of the judgment statement and the array reference position, the judgment results of the conditions and reference position are determined, and the comparison is performed to determine the abnormal detection result.
It improves the efficiency and accuracy of code detection, reduces the difficulty of detection, avoids misjudgment of the array subscript numerical range, and ensures the accuracy of array out-of-bounds detection.
Smart Images

Figure CN120346527A_ABST
Abstract
Description
Technical Field
[0001] This application relates to computer technology, and in particular, to a code detection method, apparatus, device, computer-readable storage medium, and computer program product. Background Art
[0002] In current code detection, in most cases, static code detection detects array out-of-bounds problems in static code by obtaining the range of array subscripts. However, it is difficult to obtain the numerical range of array subscripts, and the obtained numerical range may also be inaccurate. Therefore, there will be a large number of missed reports or false reports.
[0003] The related art lacks an effective solution to improve the efficiency and accuracy of code detection. Summary of the Invention
[0004] Embodiments of this application provide a code detection method, apparatus, device, computer-readable storage medium, and computer program product, which can improve the efficiency and accuracy of code detection.
[0005] The technical solution of the embodiments of this application is implemented as follows:
[0006] Embodiments of this application provide a code detection method, the method including:
[0007] Decompose the array subscript in the static code to obtain multiple decomposed subscripts corresponding to the array subscript;
[0008] Obtain the judgment statement corresponding to each of the decomposed subscripts from the static code;
[0009] Judge the decomposed subscript based on the first judgment condition corresponding to the judgment statement to obtain a condition judgment result;
[0010] Obtain the reference position of the array corresponding to the array subscript in the judgment statement, and determine a reference position judgment result based on the second judgment condition corresponding to the reference position, where the reference position is the position where the static code accesses the array in the judgment statement;
[0011] Compare the condition judgment result with the reference position judgment result, and determine an abnormal detection result of the static code according to the comparison result.
[0012] Embodiments of this application provide a code detection apparatus, including:
[0013] A decomposed subscript module, configured to decompose the array subscript in the static code to obtain multiple decomposed subscripts corresponding to the array subscript;
[0014] A judgment scenario module, configured to obtain, from the static code, a judgment statement corresponding to each of the decomposed subscripts; judge the decomposed subscripts based on a first judgment condition corresponding to the judgment statement to obtain a condition judgment result;
[0015] A judgment position module, configured to obtain a reference position of an array corresponding to the array subscript in the judgment statement, and determine a reference position judgment result based on a second judgment condition corresponding to the reference position, where the reference position is a position where the static code accesses the array in the judgment statement;
[0016] A code evaluation module, configured to compare the condition judgment result with the reference position judgment result, and determine an exception detection result of the static code according to the comparison result.
[0017] An embodiment of the present application provides an electronic device, including:
[0018] A memory, configured to store computer-executable instructions;
[0019] A processor, configured to implement the code detection method provided by the embodiment of the present application when executing the computer-executable instructions stored in the memory.
[0020] An embodiment of the present application provides a computer-readable storage medium, storing a computer program or computer-executable instructions, which are used to implement the code detection method provided by the embodiment of the present application when being executed by a processor.
[0021] An embodiment of the present application provides a computer program product, including a computer program or computer-executable instructions, where when the computer program or computer-executable instructions are executed by a processor, the code detection method provided by the embodiment of the present application is implemented.
[0022] The embodiment of the present application has the following beneficial effects:
[0023] Decompose the array subscript in the static code into multiple decomposed subscripts, without calculating the overall state of the array subscript, improving the efficiency of code detection. Judge the decomposed subscripts based on the first judgment condition corresponding to the judgment statement, and determine the reference position judgment result based on the second judgment condition corresponding to the reference position of the array corresponding to the array subscript. Determine the exception detection result of the static code through the position judgment result of the array access position and the condition judgment result. In this way, the exception detection result of the static code can be determined through two judgment conditions in the judgment statement, that is, code detection is performed through a small number of code segments, reducing the implementation difficulty of code detection and further improving the accuracy of code detection. Description of the Drawings
[0024] Figure 1It is a schematic structural diagram of the code detection system architecture provided by the embodiments of the present application;
[0025] Figure 2 It is a schematic structural diagram of the electronic device provided by the embodiments of the present application;
[0026] Figure 3A It is the first process schematic diagram of the code detection method provided by the embodiments of the present application;
[0027] Figure 3B It is the second process schematic diagram of the code detection method provided by the embodiments of the present application;
[0028] Figure 3C It is the third process schematic diagram of the code detection method provided by the embodiments of the present application;
[0029] Figure 3D It is the fourth process schematic diagram of the code detection method provided by the embodiments of the present application;
[0030] Figure 3E It is the fifth process schematic diagram of the code detection method provided by the embodiments of the present application;
[0031] Figure 3F It is the sixth process schematic diagram of the code detection method provided by the embodiments of the present application;
[0032] Figure 3G It is the seventh process schematic diagram of the code detection method provided by the embodiments of the present application;
[0033] Figure 3H It is the eighth process schematic diagram of the code detection method provided by the embodiments of the present application;
[0034] Figure 3I It is the ninth process schematic diagram of the code detection method provided by the embodiments of the present application;
[0035] Figure 3J It is the tenth process schematic diagram of the code detection method provided by the embodiments of the present application;
[0036] Figure 4 It is the code detection principle diagram provided by the embodiments of the present application;
[0037] Figure 5 It is the code scanning warning schematic diagram provided by the embodiments of the present application;
[0038] Figure 6 It is the array subscript judgment schematic diagram provided by the embodiments of the present application;
[0039] Figure 7 It is the assignment statement judgment schematic diagram provided by the embodiments of the present application;
[0040] Figure 8It is a schematic diagram of subscript decomposition provided by an embodiment of the present application;
[0041] Figure 9 It is a schematic diagram of common scenario filtering provided by an embodiment of the present application;
[0042] Figure 10 It is a schematic diagram of common scenario processing provided by an embodiment of the present application;
[0043] Figure 11 It is a schematic diagram of judgment statement processing provided by an embodiment of the present application;
[0044] Figure 12 It is the first schematic diagram of judgment position processing provided by an embodiment of the present application;
[0045] Figure 13 It is the second schematic diagram of judgment position processing provided by an embodiment of the present application. Detailed implementation manners
[0046] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on the present application. All other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of the present application.
[0047] In the following description, reference is made to "some embodiments", which describe a subset of all possible embodiments. However, it can be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.
[0048] In the following description, the terms "first / second / third" are only used to distinguish similar objects and do not represent a specific order for the objects. It can be understood that "first / second / third" can be interchanged with a specific order or sequence when allowed, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.
[0049] In the embodiments of the present application, the term "module" or "unit" refers to a computer program with a predetermined function or a part of a computer program, which works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an overall module or unit that includes the function of the module or unit.
[0050] In the embodiments of the present application, when collecting and processing relevant data in practical applications, it should strictly comply with the requirements of relevant national laws and regulations, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing behaviors within the scope authorized by laws and regulations and the personal information subject.
[0051] Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meaning as commonly understood by those skilled in the technical field to which the present application belongs. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0052] Before further elaborating on the embodiments of the present application, the nouns and terms involved in the embodiments of the present application are described, and the nouns and terms involved in the embodiments of the present application are applicable to the following explanations.
[0053] 1) Array, a linear list data structure used to store multiple data of the same type.
[0054] 2) Array out-of-bounds, which means that when accessing array elements, the subscript index exceeds the actual defined range of the array. Array out-of-bounds may access memory that does not belong to the array, resulting in abnormal program crashes.
[0055] 3) Code detection, detecting possible problems that may occur during the execution of the code. The possible problems include array out-of-bounds, code logic errors, etc.
[0056] 4) Array access, obtaining the element at a specified index within the array through the subscript of the array.
[0057] In the related art, non-static code detection determines multiple program points during the running process and uses the memory read / write detection points among the multiple program points as the starting point of the detection logic for defect detection, losing convenience. Limited by the running machine and running environment, the preparatory work in advance is relatively complex and the efficiency is relatively low.
[0058] In the related art, the detection of array out-of-bounds problems in static code is carried out by obtaining the range of array subscripts. However, it is relatively difficult to obtain the numerical range of array subscripts, and the obtained numerical range may also be inaccurate. Therefore, there will be a large number of missed reports or false reports, which is not suitable for code detection.
[0059] Based on the above analysis, the applicant found that the method of obtaining the range of array subscripts in the related art for array out-of-bounds detection cannot improve the efficiency and accuracy of code detection. In view of the above problems, the embodiments of the present application provide a code detection method, device, equipment, computer-readable storage medium, and computer program product, which can improve the efficiency and accuracy of code detection.
[0060] The following describes the exemplary applications of the electronic device provided in the embodiments of the present application. The device provided in the embodiments of the present application can be implemented as a terminal or as a server. Below, the exemplary applications when the device is implemented as a server will be described.
[0061] Refer to Figure 1 , Figure 1 which is a schematic diagram of the code detection system architecture provided in the embodiments of the present application. To support a code detection application, a terminal (exemplarily showing terminal 400) is connected to server 200 through network 300. Network 300 can be a wide area network, a local area network, or a combination of both.
[0062] The terminal 400 is used to send the static code to the server 200 through the network 300. The server 200 is used to decompose the array subscripts in the static code to obtain multiple decomposed subscripts corresponding to the array subscripts, obtain the judgment statements corresponding to each decomposed subscript, judge the decomposed subscripts based on the first judgment condition corresponding to the judgment statement to determine the condition judgment result, determine the reference position judgment result based on the second judgment condition corresponding to the reference position of the array corresponding to the array subscript, determine the abnormal detection result of the static code according to the comparison result of the condition judgment result and the reference position judgment result, and return the obtained abnormal detection result to the terminal 400. The terminal 400 displays the obtained abnormal detection result through the graphical interface 410.
[0063] The following describes an example of the terminal 400 performing code detection.
[0064] In some embodiments, the terminal 400 can independently complete the code detection task. For example, the terminal 400 is used to obtain the static code and rely on its own computing resources to decompose the array subscripts in the static code to obtain multiple decomposed subscripts corresponding to the array subscripts, obtain the judgment statements corresponding to each decomposed subscript, judge the decomposed subscripts based on the first judgment condition corresponding to the judgment statement to determine the condition judgment result, determine the reference position judgment result based on the second judgment condition corresponding to the reference position of the array corresponding to the array subscript, determine the abnormal detection result of the static code according to the comparison result of the condition judgment result and the reference position judgment result, and display the obtained abnormal detection result through the graphical interface 410.
[0065] As an example, the embodiments of the present application can be applied to code detection in the game development scenario. By detecting the static code of the game through a small number of code segments, the efficiency and accuracy of code detection are improved, and the problem of array out-of-bounds during the execution of the code, that is, during the game process, which may cause the game process to be interrupted, is avoided, thereby reducing the user's gaming experience.
[0066] In some embodiments, the server 200 may be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, Content Delivery Network (CDN), and big data and artificial intelligence platforms.
[0067] The terminal 400 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, a smart voice interaction device, a smart home appliance, a vehicle-mounted terminal, an aircraft, etc., but is not limited thereto. The terminal and the server may be directly or indirectly connected through wired or wireless communication means, which are not limited in the embodiments of the present application.
[0068] The embodiments of the present application may also be implemented through cloud technology. Cloud technology (Cloud Technology) is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model, which can form a resource pool, be used on demand, and be flexible and convenient. Cloud computing technology will become an important support. The background services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites, and more portal websites. With the high development and application of the Internet industry, and the promotion of demands such as search services, social networks, mobile commerce, and open collaboration, in the future, each item may have its own hash code identification mark, and all need to be transmitted to the background system for logical processing. Data at different levels will be processed separately, and various types of industry data require a powerful system support, which can only be achieved through cloud computing.
[0069] See Figure 2 , Figure 2 is a schematic structural diagram of an electronic device provided by the embodiments of the present application. Figure 2 The illustrated electronic device 500 may be Figure 1 the terminal 400 or the server 200 in Figure 2 . The electronic device 500 includes: at least one processor 510, a memory 550, and at least one network interface 520. Each component in the server 200 is coupled together through a bus system 540. It can be understood that the bus system 440 is used to realize the connection and communication between these components. The bus system 540 includes, in addition to a data bus, a power bus, a control bus, and a status signal bus. However, for the sake of clear illustration, in Figure 2 all kinds of buses are labeled as the bus system 540.
[0070] The processor 510 may be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or any conventional processor, etc.
[0071] The user interface 530 includes one or more output devices 531 that enable the presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 530 also includes one or more input devices 532, including user interface components that facilitate user input, such as a keyboard, a mouse, a microphone, a touch screen display, a camera, and other input buttons and controls;
[0072] In some embodiments, when the embodiment independently completes the code detection task by the terminal 400, the server 200 provided by the embodiments of the present application does not include the user interface 530.
[0073] The memory 550 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disc drives, etc. The memory 550 optionally includes one or more storage devices that are physically located away from the processor 510.
[0074] The memory 550 includes volatile memory or non-volatile memory, and may also include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 550 described in the embodiments of the present application is intended to include any suitable type of memory.
[0075] In some embodiments, the memory 550 is capable of storing data to support various operations. Examples of such data include programs, modules, and data structures, or subsets or supersets thereof, which are described below by way of example.
[0076] The operating system 551, including system programs for processing various basic system services and performing hardware-related tasks, such as the framework layer, the core library layer, the driver layer, etc., for implementing various basic services and processing hardware-based tasks;
[0077] The network communication module 552 is used to reach other computing devices via one or more (wired or wireless) network interfaces 520. Exemplary network interfaces 520 include: Bluetooth, Wi-Fi (Wireless Fidelity), and USB (Universal Serial Bus), etc.;
[0078] A presentation module 553 for enabling presentation of information (e.g., a user interface for operating a peripheral device and displaying content and information) via one or more output devices 531 associated with the user interface 530 (e.g., a display screen, a speaker, etc.);
[0079] In some embodiments, when the terminal 400 independently completes the code detection task, the server 200 provided by the embodiments of the present application may not include the presentation module 553.
[0080] An input processing module 554 for detecting and translating one or more user inputs or interactions from one of one or more input devices 532; in some embodiments, when the terminal 400 independently completes the code detection task, the server 200 provided by the embodiments of the present application may not include the presentation module 553.
[0081] In some embodiments, the device provided by the embodiments of the present application may be implemented in software. Figure 2 Shows a code detection device 555 stored in the memory 550, which may be software in the form of a program and a plug-in, etc., including the following software modules: a subscript decomposition module 5551, a scenario judgment module 5552, a position judgment module 5553, a code evaluation module 5554, a code acquisition module 5555, an assignment statement processing module 5556, a scenario filtering 55557. These modules are logical, so they can be combined arbitrarily or further split according to the implemented functions. The functions of each module will be described below.
[0082] In other embodiments, the device provided by the embodiments of the present application may be implemented in hardware. As an example, the device provided by the embodiments of the present application may be a processor in the form of a hardware decoding processor, which is programmed to execute the image processing method provided by the embodiments of the present application. For example, the processor in the form of a hardware decoding processor may employ one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field programmable gate arrays (FPGAs) or other electronic components.
[0083] It should be noted that in the examples of code detection below, those skilled in the art can apply the code detection method provided in the embodiments of the present application to code detection processing according to the understanding of the following text.
[0084] See Figure 3A , Figure 3A is the first process schematic diagram of the code detection method provided in the embodiments of the present application, and will be described in combination with Figure 3A the steps shown. The video playback method provided in the embodiments of the present application can be implemented independently by a server or a terminal, or jointly implemented by a server and a terminal. Below, an example of joint implementation by a server and a terminal will be used for description.
[0085] In step 101, decompose the array subscript in the static code to obtain multiple decomposed subscripts corresponding to the array subscript.
[0086] In some embodiments, the array subscript in the static code is a complex expression. Decompose the array subscript to obtain the decomposed subscripts in the array subscript. The decomposed subscripts can be various basic expressions. Among them, the complex expression contains multiple (at least two) basic expressions and arithmetic expressions for connecting multiple (at least two) basic expressions.
[0087] For example, the array subscript is b + 1. Decompose the array subscript to obtain the basic expressions b and 1, that is, obtain the decomposed subscripts b and 1 corresponding to the array subscript.
[0088] In some embodiments, the array subscript in the static code is a basic expression, and the array subscript in the static code is determined as the decomposed subscript.
[0089] For example, the array subscript is b. Decompose the array subscript to obtain the basic expression b, that is, obtain the decomposed subscript b corresponding to the array subscript.
[0090] In some embodiments, iteratively execute the following processing. See Figure 3B , Figure 3B which is the second process schematic diagram of the code detection method provided in the embodiments of the present application. Figure 3A The step 101 shown can be implemented through Figure 3B steps 1011 to 1013 below. The following is a specific description.
[0091] In step 1011, determine the iteration object of the current iteration. Among them, the iteration object of the current iteration is the decomposition result of the iteration object of the previous iteration, and the iteration object of the first iteration is the array subscript.
[0092] In some embodiments, decompose the iteration object based on the arithmetic expression in the iteration object, where the iteration object is an expression that needs to be subscript decomposed.
[0093] Exemplarily, the array subscript is a + b. Taking the array subscript a + b as the iteration object for the first iteration, the array subscript is decomposed to obtain the decomposition results a and b for the first iteration. Taking the decomposition results a and b as the iteration objects for the second iteration.
[0094] Exemplarily, the array subscript is a + b * c. Taking the array subscript a + b * c as the iteration object for the first iteration, the array subscript is decomposed to obtain the decomposition results a and b * c for the first iteration. Taking the decomposition results a and b * c as the iteration objects for the second iteration. Since the decomposition result b * c still contains the arithmetic expression "*", the decomposition result b * c is decomposed to obtain the decomposition results b and c for the second iteration. Taking the decomposition results b and c as the iteration objects for the third iteration.
[0095] In step 1012, when the iteration object of the current iteration includes an arithmetic expression, the iteration object of the current iteration is decomposed based on the arithmetic expression to obtain the decomposition result of the current iteration, and the decomposition result of the current iteration is used as the iteration object for the next iteration, and the iteration continues.
[0096] In some embodiments, when the iteration object includes an arithmetic expression, the expression on the left side of the arithmetic expression and the expression on the right side of the arithmetic expression in the iteration object are used as the decomposition results of the current iteration, where the arithmetic expression includes basic operation methods such as addition, subtraction, multiplication, and division.
[0097] Exemplarily, the iteration object of the current iteration is a + b. The expression a on the left side of the arithmetic expression "+" and the expression b on the right side of the arithmetic expression in the iteration object a + b are used as the decomposition results of the current iteration. Taking the decomposition results a and b of the current iteration as the iteration objects for the next iteration.
[0098] In step 1013, when the iteration object of the current iteration does not include an arithmetic expression, the iteration object of the current iteration is used as the decomposition subscript, and the iteration ends.
[0099] Exemplarily, the iteration object a + b of the previous iteration is decomposed to obtain the iteration objects a and b of the current iteration. Since the iteration objects a and b of the current iteration do not include an arithmetic expression, a and b are used as the decomposition subscripts, and the iteration ends.
[0100] Through the embodiments of the present application, the array subscript is decomposed into multiple decomposition subscripts, without calculating the overall state of the array subscript, improving the efficiency of code detection. At the same time, obtaining the numerical range of the array subscript is avoided, reducing the probability of misjudging array out-of-bounds based on the array subscript range. The state of the array subscript is obtained based on multiple decomposition subscripts, improving the accuracy of code detection.
[0101] In some embodiments, referring to Figure 3C , Figure 3C is the third process schematic diagram of the code detection method provided by the embodiments of the present application. Before step 102, perform Figure 3C steps 201 to 202, which are specifically described below.
[0102] In step 201, obtain the data type of the decomposed subscript.
[0103] In some embodiments, the data type of the decomposed subscript includes basic data types and reference data types. Different data types are used to represent that the corresponding data has different storage spaces. The embodiments of the present application do not limit the data type of the decomposed subscript.
[0104] In step 202, when the data type does not belong to a specific data type, determine that the operation of obtaining the judgment statement corresponding to each decomposed subscript will be executed.
[0105] Among them, the specific data types include constants, enumerations, array lengths, and macro definitions.
[0106] In some embodiments, when the data type belongs to a specific data type, do not execute the operation of obtaining the judgment statement corresponding to each decomposed subscript, and directly determine that the exception detection result corresponding to the decomposed subscript is normal.
[0107] For example, in the array access statement a[3]=1, the array subscript is the constant 3, that is, the decomposed subscript after subscript decomposition is the constant 3. Do not execute the operation of obtaining the judgment statement corresponding to each decomposed subscript, and directly determine that the exception detection result corresponding to the decomposed subscript is normal.
[0108] Through the embodiments of the present application, judge the data type of the decomposed subscript, and only perform further array out-of-bounds judgment on the decomposed subscripts of non-specific data types, reducing the time of code detection, thereby further improving the efficiency of code detection.
[0109] Continuing to refer to Figure 3A , in step 102, obtain the judgment statement corresponding to each decomposed subscript from the static code.
[0110] In some embodiments, obtain the judgment statement containing each decomposed subscript from the static code, where the judgment statement is used to perform out-of-bounds judgment on the decomposed subscript.
[0111] For example, if one of the decomposed subscripts is A, in the code if(A>0), obtain the judgment statement A>0 corresponding to the decomposed subscript A. 0 is the lower bound of the decomposed subscript A, and the judgment statement A>0 is used to judge whether the decomposed subscript A is out of bounds. When A is less than or equal to 0, the decomposed subscript A is out of bounds.
[0112] In step 103, the decomposition subscript is judged based on the first judgment condition corresponding to the judgment statement, and a condition judgment result is obtained.
[0113] In some embodiments, the judgment statement includes a first judgment condition that defines the array boundary of the decomposition subscript. The condition judgment result of the judgment statement corresponding to the decomposition subscript can be obtained according to the first judgment condition. The condition judgment result is used to indicate the comparison relationship between the decomposition subscript and the array boundary, and the condition judgment result is one of the four states: greater than zero, less than zero, greater than the maximum value, and less than the maximum value.
[0114] In some embodiments, refer to Figure 3D , Figure 3D is the fourth process schematic diagram of the code detection method provided by the embodiments of the present application. Figure 3A The steps shown in step 103 can be implemented by Figure 3D steps 1031 to 1034 below will be specifically described.
[0115] In step 1031, the first judgment condition of the judgment statement is obtained from the static code.
[0116] In some embodiments, a judgment statement is obtained from the static code. The judgment statement includes a statement for judging whether the decomposition subscript is out of bounds, that is, the first judgment condition.
[0117] For example, in the judgment statement of if(a>0), the first judgment condition a>0 of the judgment statement is obtained, where a>0 is used to judge whether the value of the decomposition subscript a exceeds the lower bound 0.
[0118] In step 1032, when the first judgment condition includes multiple conditional expressions and the multiple conditional expressions are in an AND relationship, the decomposition subscript is judged based on the conditional expressions, and the judgment result corresponding to each conditional expression is obtained, and the intersection of the judgment results corresponding to the conditional expressions is determined as the condition judgment result.
[0119] Here, when the first judgment condition includes multiple conditional expressions and the multiple conditional expressions are in an AND relationship, the multiple conditional expressions in the first judgment condition are obtained. For example, in the first judgment condition of a>0&&a<100, the two expressions a>0 and a<100 of the first judgment condition are respectively obtained.
[0120] Continuing with the above example, the decomposed subscript is judged according to each conditional expression to obtain the corresponding judgment result. It should be noted that when the expression contains a relational operator, the judgment result of the conditional expression is determined according to the relational operator, the position of the decomposed subscript in the expression, and the expression on the other side of the relational operator corresponding to the position where the decomposed subscript is located. Among them, the judgment result is one of the four states of greater than zero, less than zero, greater than the maximum value, and less than the maximum value. For example, in the conditional expression of a > 0, the decomposed subscript a is on the left side of the relational operator ">", and the expression 0 on the right side of the relational operator is obtained. Also, since the relational operator is a greater than operation, the judgment condition of the conditional expression is greater than zero. For example, in the conditional expression of a < 100, the decomposed subscript a is on the left side of the relational operator "<", and the expression 100 on the right side of the relational operator is obtained. Also, since the relational operator is a less than operation, the judgment condition of the conditional expression is less than the maximum value.
[0121] Continuing with the above example, the intersection of the judgment results corresponding to the conditional expressions is determined as the conditional judgment result. For example, in the first judgment condition of a > 0 && a < 100, the judgment condition of a > 0 is obtained as greater than zero, and the judgment condition of a < 100 is obtained as less than the maximum value. The intersection of the judgment results, that is, greater than zero and less than the maximum value, is used as the conditional judgment result of the judgment statement.
[0122] In step 1033, when the first judgment condition includes multiple conditional expressions and the multiple conditional expressions are in an "or" relationship, the decomposed subscript is judged according to the conditional expressions to obtain the judgment result corresponding to each conditional expression, and the union of the judgment results corresponding to the conditional expressions is determined as the conditional judgment result.
[0123] Here, when the first judgment condition includes multiple (at least two) conditional expressions and the multiple conditional expressions are in an "or" relationship, the multiple conditional expressions in the first judgment condition are obtained. For example, in the first judgment condition of a > 0 || a > 100, the two expressions a > 0 and a > 100 of the first judgment condition are obtained respectively.
[0124] Continuing with the above example, the decomposed subscript is judged according to each conditional expression to obtain the corresponding judgment result. It should be noted that when the expression contains a relational operator, the judgment result of the conditional expression is determined according to the relational operator, the position of the decomposed subscript in the expression, and the expression on the other side of the relational operator corresponding to the position where the decomposed subscript is located. Among them, the judgment result is one of the four states of greater than zero, less than zero, greater than the maximum value, and less than the maximum value. For example, in the conditional expression of a > 0, the decomposed subscript a is on the left side of the relational operator ">", and the expression 0 on the right side of the relational operator is obtained. Also, since the relational operator is a greater than operation, the judgment condition of the conditional expression is greater than zero. For example, in the conditional expression of a > 100, the decomposed subscript a is on the left side of the relational operator ">", and the expression 100 on the right side of the relational operator is obtained. Also, since the relational operator is a greater than operation, the judgment condition of the conditional expression is greater than the maximum value.
[0125] Continuing with the above example, the union of the judgment results corresponding to the conditional expressions is determined as the conditional judgment result. For example, in the first judgment condition of a > 0 || a > 100, the judgment condition of a > 0 is obtained as greater than zero, and the judgment condition of a > 100 is obtained as greater than the maximum value. The union of the judgment results, that is, greater than zero, is used as the conditional judgment result of the judgment statement.
[0126] In step 1034, when the first judgment condition includes only one conditional expression, the decomposed subscript is judged based on one conditional expression to obtain the conditional judgment result.
[0127] In some embodiments, the conditional judgment result is one of the four states of greater than zero, less than zero, greater than the maximum value, and less than the maximum value.
[0128] For example, the first judgment condition includes only the conditional expression of a > 0. The judgment condition of the conditional expression is obtained as greater than zero, and the state of greater than zero is determined as the conditional judgment result corresponding to the judgment statement.
[0129] In some embodiments, refer to Figure 3E , Figure 3E is the fifth process schematic diagram of the code detection method provided by the embodiments of the present application. For Figure 3D the judgment of the decomposed subscript based on one conditional expression in step 1034 to obtain the conditional judgment result can be implemented through Figure 3E steps 10341 to 10344.
[0130] In step 10341, when a conditional expression contains a relational operator, determine the position of the decomposed subscript in the conditional expression, and determine the judgment result corresponding to the position as the conditional judgment result.
[0131] In some embodiments, the decomposed subscript at the position of the conditional expression is used to characterize whether the decomposed subscript is on the left or right side of the relational operator. When the decomposed subscript is on the left side of the relational operator, the judgment result of the conditional expression is determined according to the relational operator and the expression on the right side of the relational operator, and the judgment result of the conditional expression is determined as the conditional judgment result. Among them, the judgment result of the conditional expression is one of four states: greater than zero, less than zero, greater than the maximum value, and less than the maximum value.
[0132] Exemplarily, in the conditional expression a > 0, since a is on the left side of the relational operator ">", the judgment result of the conditional expression is determined to be greater than zero according to the relational operator ">" and the expression 0 on the right side of the relational operator, and the judgment result greater than zero is determined as the conditional judgment result.
[0133] In some embodiments, when the decomposed subscript is on the right side of the relational operator, the judgment result of the conditional expression is determined according to the relational operator and the expression on the right side of the relational operator, and the result opposite to the judgment result of the conditional expression is determined as the conditional judgment result. Among them, the judgment result of the conditional expression is one of four states: greater than zero, less than zero, greater than the maximum value, and less than the maximum value.
[0134] Exemplarily, in the conditional expression 0 > a, since a is on the right side of the relational operator ">", the judgment result of the conditional expression is determined to be greater than zero according to the relational operator ">" and the expression 0 on the right side of the relational operator, and the result opposite to the judgment result greater than zero, which is less than zero, is determined as the conditional judgment result.
[0135] It should be noted that the opposite result here is not the complement of the judgment result. The opposite result of greater than zero is less than zero, and the opposite result of greater than the maximum value is less than the maximum value.
[0136] In step 10342, when a conditional expression contains a logical NOT operator, the judgment result opposite to the conditional expression is determined as the conditional judgment result.
[0137] In some embodiments, the logical NOT operator is used to obtain a result opposite to the judgment result of the conditional expression.
[0138] Exemplarily, in the conditional expression!(a > 0), the judgment result of the conditional expression a > 0 is obtained as greater than zero, and the result opposite to the judgment result greater than zero, which is less than zero, is determined as the conditional judgment result.
[0139] In step 10343, an expression set matching the decomposed subscript is obtained.
[0140] Among them, the expression set includes a first expression in the same assignment statement as the decomposition subscript, and a second expression in the same assignment statement as the first expression.
[0141] In some embodiments, traverse the assignment statements, and place two expressions in an assignment statement in an expression set, that is, fuse the expression sets corresponding to the two expressions into one expression set, where any two expressions in the expression set have the same judgment result.
[0142] For example, in the assignment statement d = b, form an expression set with expressions d and b. In the assignment statement c = d, the expression set corresponding to c <c>The set of expressions <d, b> corresponding to d forms a new set of expressions <d, b, c>, that is, the set of expressions contains the first expression d in the same assignment statement as the decomposition subscript c, and the second expression b in the same assignment statement as the first expression d.
[0143] In step 10344, when a conditional expression contains any expression in the set of expressions and a conditional expression does not contain a decomposition subscript, the judgment result of the conditional expression is determined as the conditional judgment result.
[0144] In some embodiments, since any two expressions in the set of expressions have the same judgment result, the judgment result of any expression in the set of expressions included in the conditional expression can be determined as the conditional judgment result.
[0145] For example, the set of expressions corresponding to the decomposition subscript c is <d, b, c>. In the judgment statement if(b>0){a[c]=1}, the judgment result for the expression b is greater than zero. Since the decomposition subscript and the expression b are in the same set of expressions, the judgment result of the expression b being greater than zero is used as the judgment result of the decomposition subscript, that is, the conditional judgment result.
[0146] Through the embodiments of the present application, the conditional judgment result corresponding to the decomposition subscript is determined in different types of judgment statements, and it is determined to judge the decomposition subscript in various judgment statement scenarios, avoiding the situation of missed judgment of the decomposition subscript, and further improving the accuracy of code detection.
[0147] Continue to refer to Figure 3A , in step 104, obtain the reference position of the array corresponding to the array subscript in the judgment statement, and determine the reference position judgment result based on the second judgment condition corresponding to the reference position.
[0148] Among them, the reference position is the position where the static code accesses the array in the judgment statement.
[0149] In some embodiments, the reference position of the array corresponding to the array subscript in the judgment statement is the position where the static code accesses the array. In the judgment statement, the referenced position corresponds one-to-one with the second judgment condition, that is, when the decomposition subscript meets the second judgment condition, the judgment condition position of the judgment statement can jump to the reference position of the array when the code is executed.
[0150] In some embodiments, when the judgment statement contains an array subscript and the array name corresponding to the array subscript, the position of the array name is determined as the reference position.
[0151] In some embodiments, each code segment of the traversed judgment statement is traversed. When the code segment contains an array subscript and the array name corresponding to the array subscript, the position of the array name is determined as the reference position.
[0152] For example, in the code segment of the judgment statement a>0&&a<100&&a[b]=1, the array subscript b and the array name a are included on the right side of the relational operator, and the array name a is determined as the reference position of the array.
[0153] In some embodiments, refer to Figure 3F , Figure 3F is the sixth process schematic diagram of the code detection method provided by the embodiments of the present application. Before determining the reference position judgment result based on the second judgment condition corresponding to the reference position in step 104, execute Figure 3F Steps 301 to 302 of , which will be specifically described below.
[0154] In step 301, when the jump position corresponding to the execution of the conditional expression in the judgment statement matches the reference position, the conditional expression is determined as the second judgment condition.
[0155] In some embodiments, when the jump position corresponding to the execution of the conditional expression in the judgment statement matches the reference position, that is, the jump position and the reference position are the same position in the static code, the conditional expression is determined as the second judgment condition, where the jump position corresponding to the execution of the conditional expression in the judgment statement may point to a position different from the reference position according to the type of the judgment statement.
[0156] For example, in the judgment statement if(b>0){a[b+c]=1}, when the conditional expression b>0 in the judgment statement is executed, it jumps to the position of a[b+c]=1. Among them, the array subscript is b+c, and a[b+c]=1 contains the decomposed subscript b and the array name a. It can be determined that the array corresponding to the array subscript, that is, the array corresponding to the decomposed subscript b included in the array subscript. Since a[b+c]=1 contains the decomposed subscript b and the array name a of the array corresponding to the decomposed subscript b, a[b+c]=1 is also the reference position of the array access. Therefore, the jump position corresponding to the execution of the conditional expression in the judgment statement and the reference position are the same position, that is, the jump position and the reference position match, and the conditional expression b>0 is determined as the second judgment condition.
[0157] In step 302, when the jump position corresponding to the execution of the conditional expression in the judgment statement does not match the reference position, the complement of the conditional expression is determined as the second judgment condition.
[0158] In some embodiments, when the jump position corresponding to the execution of the conditional expression in the judgment statement does not match the reference position, that is, the jump position and the reference position are different positions in the static code, the complement set of the conditional expression is determined as the second judgment condition, where the jump position corresponding to the execution of the conditional expression in the judgment statement may point to a position different from the reference position according to the type of the judgment statement.
[0159] For example, in the judgment statement if(b>0){pass}else{a[b]=1}, when the conditional expression b>0 in the judgment statement is executed, it jumps to the position of pass. a[b]=1 in the judgment statement is the reference position of the array access. The reference position of the array access is the jump position for executing the conditional expression opposite to the conditional expression when the conditional expression b>0 in the judgment statement cannot be executed. The jump position corresponding to the execution of the conditional expression in the judgment statement and the reference position are different positions, that is, the jump position and the reference position do not match. The conditional expression opposite to the conditional expression b>0, that is, the conditional expression b less than or equal to 0, is determined as the second judgment condition.
[0160] Through the embodiments of the present application, the judgment of the decomposed subscript is based on the reference position of the array access, avoiding determining the numerical range corresponding to the array subscript when accessing the array through a large amount of calculations, and only performing code detection through a small number of code segments, reducing the implementation difficulty of code detection.
[0161] Continue to refer to Figure 3A , in step 105, the conditional judgment result is compared with the reference position judgment result, and the abnormal detection result of the static code is determined according to the comparison result.
[0162] In some embodiments, when the conditional judgment result is exactly equal to the reference position judgment result, or the similarity between the conditional judgment result and the reference position judgment result is greater than or equal to a preset similarity threshold, the abnormal detection result of the static code is determined to be normal; otherwise, the abnormal detection result of the static code is determined to be abnormal.
[0163] In some embodiments, referring to Figure 3G , Figure 3G is the seventh process schematic diagram of the code detection method provided by the embodiments of the present application. Figure 3A The step 105 shown can be implemented by Figure 3G steps 1051 to 1052, which will be specifically described below.
[0164] In step 1051, when the conditional judgment result matches the reference position judgment result, the abnormal detection result of the static code is determined to be normal.
[0165] In some embodiments, the similarity between the condition judgment result and the reference position judgment result can be determined. When the similarity is greater than or equal to a preset similarity threshold, the condition judgment result matches the reference position judgment result, and the abnormal detection result of the static code is determined to be normal.
[0166] For example, when the condition judgment result is greater than zero and the reference position judgment result is greater than zero, the similarity between the condition judgment result and the reference position judgment result is determined to be 1. Since the similarity 1 is greater than the similarity threshold 0.85, the condition judgment result matches the reference position judgment result, and the abnormal detection result of the static code is determined to be normal.
[0167] In step 1052, when the condition judgment result does not match the reference position judgment result, the abnormal detection result of the static code is determined to be abnormal.
[0168] In some embodiments, the similarity between the condition judgment result and the reference position judgment result can be determined. When the similarity is less than the preset similarity threshold, the condition judgment result does not match the reference position judgment result, and the abnormal detection result of the static code is determined to be abnormal.
[0169] For example, when the condition judgment result is greater than zero and the reference position judgment result is less than the maximum value, the similarity between the condition judgment result and the reference position judgment result is determined to be 0. Since the similarity 0 is less than the similarity threshold 0.85, the condition judgment result does not match the reference position judgment result, and the abnormal detection result of the static code is determined to be abnormal.
[0170] Through the embodiments of the present application, the reference position judgment result corresponding to the reference position is compared with the condition judgment result, and whether the array access exceeds the boundary is judged based on the comparison result. In this way, the accuracy of the array out-of-bounds detection is ensured, and the numerical judgment of the array is avoided when referring to the array access, improving the efficiency and accuracy of the code detection.
[0171] In some embodiments, refer to Figure 3H , Figure 3H is the eighth process schematic diagram of the code detection method provided by the embodiments of the present application. After step 105, execute Figure 3H steps 401 to 402 below, which will be specifically described.
[0172] In step 401, obtain the abnormal detection results corresponding to each decomposed subscript.
[0173] In some embodiments, the abnormal detection result corresponding to the decomposed subscript is used to judge whether the decomposed subscript exceeds the boundary. If the abnormal detection result of the static code is abnormal, the decomposed subscript has exceeded the boundary. If the abnormal detection result of the static code is normal, the decomposed subscript has not exceeded the boundary.
[0174] In step 402, when any anomaly detection result is an anomaly, an alarm message is output, and the alarm message is used to indicate that there is an array out-of-bounds anomaly in the static code.
[0175] In some embodiments, when it is detected that any anomaly detection result is an anomaly, an alarm message is output so that the user can quickly modify the static code based on the alarm message. Among them, the output alarm message includes the array access position corresponding to the anomaly detection result.
[0176] Through the embodiments of the present application, when it is detected that any anomaly detection result is an anomaly, an alarm message is output so that the user can quickly modify the code based on the alarm message.
[0177] In some embodiments, refer to Figure 3I , Figure 3I is the ninth process schematic diagram of the code detection method provided by the embodiments of the present application. Before step 101, execute Figure 3I steps 501 to 502 of
[0178] In step 501, obtain the static code from the code file.
[0179] In some embodiments, static code refers to the code in a code file without executing the code.
[0180] In step 502, when there is a code segment for array access in the static code, obtain the array subscript in the static code from the code segment.
[0181] In some embodiments, traverse the code segments of the static code. When a code segment in the static code is for array access, obtain the array name and array subscript in the code segment.
[0182] Exemplarily, the static code includes an array access code segment of a[b]=1, where b is the array subscript and a is the array name. When traversing to a[b]=1, obtain the array subscript b.
[0183] In some embodiments, refer to Figure 3J , Figure 3J is the tenth process schematic diagram of the code detection method provided by the embodiments of the present application. After step 502, execute Figure 3J steps 601 to 604 of
[0184] In step 601, obtain the assignment statement in the static code.
[0185] In some embodiments, the two expressions in the assignment statement have the same state, that is, the expression being assigned and the assignment expression have the same state.
[0186] In step 602, when the assignment statement does not include a modulo operation, the status of the assigned expression in the assignment statement is determined as the status of the assignment expression in the assignment statement.
[0187] Wherein, the type of the assigned expression is a separate variable, and the status of the assignment expression is an undetermined status or a determined status.
[0188] In some embodiments, when the assignment statement does not include a modulo operation, the status of the assigned expression is determined based on the status of the assignment expression.
[0189] For example, when the assignment statement is A = B, the status of the assigned expression A in the assignment statement is determined as the status of the assignment expression B, where A represents the assigned expression in the assignment statement and B represents the assignment expression in the assignment statement.
[0190] For example, when the status of the assignment expression B is determined, the status of the assigned expression A is determined as determined, and when the status of the assignment expression B is undetermined, the status of the assigned expression A is determined as undetermined.
[0191] In some embodiments, when the assignment statement includes a modulo operation, the status of the assigned expression in the assignment statement is determined as determined.
[0192] For example, when the assignment statement is A %= B, that is, when performing the modulo operation of A = A % B, the status of the assigned expression A in the assignment statement is determined as determined, where A represents the assigned expression in the assignment statement and B represents the assignment expression in the assignment statement.
[0193] In some embodiments, when the assigned expression includes a decomposed subscript, the status of the decomposed subscript is determined as determined, and the abnormal detection result corresponding to the decomposed subscript is determined as normal.
[0194] In step 603, when the assigned expression includes an array subscript, the status of the array subscript is determined as the status of the assigned expression.
[0195] In some embodiments, when the assigned expression includes an array subscript, if the status of the assigned expression is undetermined, the status of the array subscript is determined as undetermined, and if the status of the assigned expression is determined, the status of the array subscript is determined as determined.
[0196] In some embodiments, since the assigned expression is a variable, when the assigned expression includes an array subscript, the array subscript is also a variable.
[0197] In step 604, when the status of the array subscript is in an undetermined state, it is determined that an operation of decomposing the array subscript in the static code will be performed.
[0198] In some embodiments, when the status of the array subscript is the undetermined status, it is necessary to further judge the array subscript and perform an operation of decomposing the array subscript in the static code, and decompose the array subscript into multiple (at least two) decomposed subscripts.
[0199] In some embodiments, when the status of the array subscript is the determined status, the operation of decomposing the array subscript in the static code is not performed, and the abnormal detection result corresponding to the array subscript is determined to be normal.
[0200] Through the embodiments of the present application, it is not necessary to calculate the status related to the array subscript in each step. By pre-obtaining the status of the expression in the assignment statement, the array subscript can be filtered based on the status of the array subscript, thereby improving the efficiency of code detection.
[0201] Next, an exemplary application of the code detection method provided by the embodiments of the present application in an actual application scenario will be described.
[0202] In the application scenario of code detection, the code detection methods in the related art are mainly divided into the following two types: static code detection methods and non-static code detection methods. Among them, the static code detection method refers to analyzing and checking the code without executing the code, and discovering problems or defects in the code through static analysis of the code and program structure.
[0203] The static code scanning method in the related art needs to obtain the value range of the predetermined variable of the array accessed by the target program statement within the program area corresponding to the array. However, it is difficult to obtain the value range, and the obtained value range may also be inaccurate. Therefore, there will be a large number of missed reports or false reports.
[0204] The non-static code scanning in the related art determines multiple program points during the running process, and uses the memory read and write detection points among the multiple program points as the starting point of the detection logic for defect detection. Compared with the static code scanning, it loses convenience, is limited by the running machine and running environment, and the pre-preparation of the entire scanning process is relatively complex, and the efficiency is relatively low.
[0205] Therefore, in the embodiments of the present application, based on the decomposed array subscript in the static code for out-of-bounds check, a new code detection method is proposed, which can discover the hidden array out-of-bounds in the code, effectively discover the situations where array out-of-bounds vulnerabilities may occur in the code, and greatly improve the efficiency and accuracy of code scanning data out-of-bounds.
[0206] Through the code detection method provided by the embodiments of the present application, the array subscripts in the code (i.e., static code) are decomposed to obtain multiple decomposed subscripts corresponding to the array subscripts, the judgment statements corresponding to each decomposed subscript are obtained, the decomposed subscripts are judged based on the conditional expressions corresponding to the judgment statements (i.e., the above first judgment condition), the corresponding results are returned, and based on the conditional expression corresponding to the reference position of the array corresponding to the array subscript (i.e., the above second judgment condition), the judgment result of the reference position (i.e., the above reference position judgment result) is determined, and the status of the decomposed subscript is determined according to the result of the conditional judgment and the judgment result of the reference position.
[0207] Taking code detection as an example, see Figure 4 , Figure 4 which is the schematic diagram of code detection provided by the embodiments of the present application.
[0208] In Figure 4 , first confirm whether the code involves array access. If there is an array access situation, obtain the array name and the array subscript, then judge the array subscript. If a check has been made in advance, no warning is required. Otherwise, further check is needed to confirm whether there is a risk of out-of-bounds access.
[0209] void f(char a[], int b) {
[0210] a[b] = 1; / / Array access
[0211] }
[0212] As shown in the above code, where a[b] is a typical array access. Among them, a is the array name, b is the subscript, f is the function name, void is used to indicate that the value returned by the function is null. The function is to perform an array access on the array with the array name a and assign a value to the value with the subscript b in the array. If b is judged in the code, no warning will be given, otherwise a warning will be given.
[0213] When the code detection method provided by the embodiments of the present application detects that there is a risk of out-of-bounds access in the code, an alarm message is output. See Figure 5 , Figure 5 which is the schematic diagram of code scanning and warning provided by the embodiments of the present application. As shown in Figure 5 , the code file is obtained, and the code file is scanned using a code scanning tool, and the scanned code is detected based on multiple rules. The embodiments of the present application provide a code detection method, that is, the rules for detecting the scanned code. When the scanned code conforms to the relevant characteristics of the rules, an alarm message is output.
[0214] Continue to refer to Figure 4 , when performing array subscript judgment, process the assignment statements in the static code to obtain the states of all expressions in the assignment statements. The expressions in the assignment statements include the expressions corresponding to the array subscripts being assigned. Then decompose the array subscripts. For several common scenarios, it is generally assumed that the judgment and analysis have been done, and they are directly filtered. Then perform judgment scenario processing and judgment position processing on the decomposed subscripts. Finally, give a judgment result based on the comprehensive analysis.
[0215] According to the filtering of the mentioned common scenarios, it refers to 4 common array access situations, which are defaulted to have been judged and will not generate warnings. The specific scenarios include: array access situations where the subscript is an enumeration, array access situations where the subscript is a constant, array access situations where the subscript is a macro, and array access situations where the subscript is the length of an array name.
[0216] According to the mentioned judgment scenario processing, query the variable state corresponding to the decomposed subscript. If the variable state has not been judged, then look for judgment statements and query whether there are 4 situations in the static code, such as "if / while / for statements", "&& expressions", "|| expressions", or "? expressions". If there is a judgment situation, perform judgment statement processing on the decomposed subscript.
[0217] According to the mentioned judgment position processing, there are three forms of position judgment, namely the down form, the mid form, and the else form. Among them, the down form is that the array reference statement is below the influence of the judgment statement, the mid form is that the array reference statement is in the middle of the influence of the judgment statement, and the else form is that the array reference statement is in the else block of the judgment statement.
[0218] See Figure 6 , Figure 6 is a schematic diagram of array subscript judgment provided by an embodiment of the present application. As Figure 6 shown, first perform assignment statement processing and store the states of all expressions in the assignment statements. Among them, the expressions in the assignment statements include the expressions corresponding to the array subscripts being assigned. Then for the case where the array subscript is a complex expression, decompose the array subscript into multiple decomposed subscripts, and then perform judgment on each decomposed subscript. If the decomposed subscript belongs to a common scenario, filter the decomposed subscript. Based on the judgment statements in the static code, judge whether the decomposed subscript is processed for judgment scenarios. If the judgment scenario processing has been performed, then it is necessary to process the position of the judgment array access, and finally return the result.
[0219] See Figure 7 , Figure 7 is a schematic diagram of assignment statement judgment provided by an embodiment of the present application. As Figure 7 As shown, there are two cases for the assignment statement that need to be processed. One is the case of A = B, and the other is the case of A %= B, that is, A = A % B. Here, A and B are the assigned expression and the assignment expression used for assignment.
[0220] As Figure 7 shown, perform path judgment on the assignment statement. Here, path judgment refers to the path from the assignment statement to array access. When the assigned expression in the assignment statement cannot access the array, that is, when there is no path for array access in the assignment statement, then do not perform judgment on the assignment statement, end the processing of the assignment statement, and return to the next processing position of the assignment statement. When the assigned expression in the assignment statement can access the array, it is divided into a necessary path that must be reached and a possible path according to the situation of accessing the array by the assignment statement.
[0221] As Figure 7 shown, for the case of A %= B, directly set A to the judged state. For the case of A = B, if it is on the necessary path, then query the judgment situation of B and the adjacent state of B. Here, the judgment situation of B is whether the state of B is judged, and the adjacent state of B is the query situation of B in the state list. If the state of B is judged, then set A and B to the same state. After all, the states of A and B are both marked as judged; for the possible path, if A is equal to the subscript to be judged, then check the state of A. If the current state of A is judged, then reset A, set A and B to the same state, otherwise keep it unchanged, that is, the state of A remains unjudged.
[0222] Continue to refer to Figure 6 , when using the array subscript, it may be a complex expression and needs to be decomposed. The main way to decompose it is to decompose arithmetic operations. Refer to Figure 8 , Figure 8 is the schematic diagram of subscript decomposition provided by the embodiment of the present application. As Figure 8 shown, to decompose the expression corresponding to the array subscript into basic expressions, first judge whether the array subscript is an arithmetic expression (+ - * / ). If so, decompose its left operand and right operand again until it becomes a basic expression.
[0223] void f(char a[], int b) {
[0224] a[b + 1] = 1; / / Decompose into two basic expressions b and 1
[0225] }
[0226] As shown in the above code, a[b + 1] is a typical array access, where a is the array name, b is the array subscript, f is the function name, void is used to indicate that the value returned by the function is null. The function's role is to perform an array access on the array named a and assign a value to the element with subscript b in the array, and decompose the subscript b + 1 into two basic expressions b and 1.
[0227] Continue to refer to Figure 6 , in the actual usage process, some common scenarios are also considered to have been judged. See Figure 9 , Figure 9 is the schematic diagram of common scenario filtering provided by the embodiments of the present application. As Figure 9 shown, if one of the following four cases occurs: using a macro as a subscript, using an enumeration as a subscript, using a constant as a subscript, or using the length of an array name as a subscript, it is considered that the decomposed subscript has been judged and no warning will be issued.
[0228]
[0229] Among them, #define is used to indicate that the value of the macro definition M of the code is 1, a is the array name, b is the subscript, f is the function name, void is used to indicate that the value returned by the function is null, enum is an enumeration data type used to define a set of constants with discrete values, C is the enumeration name, and C1 is the enumeration constant included in the enumeration. The sizeof() function is used to calculate the length of the array.
[0230] See Figure 10 , Figure 10 is the schematic diagram of common scenario processing provided by the embodiments of the present application. As Figure 10 shown, for the decomposed subscript, the state of the decomposed subscript will be judged. If it is already in the judged state, the judged result will be directly returned. Otherwise, the conditional statement used for judgment will be searched, that is, the judgment statement. If an if / while / for statement is found, its conditional expression will be obtained and further processed. If the place of array reference is within the conditional statement corresponding to one of the three conditional expressions of "&& expression", "|| expression", or "? expression", the previous conditional judgment information needs to be processed, that is, its previous conditional expression.
[0231]
[0232] It can be determined from the above code that the reference position of the conditional statement corresponding to the "&& expression" must be after "&&", the part before "&&" is the conditional expression, the reference position of the conditional statement corresponding to the "|| expression" must be after "||", and the part before the conditional statement corresponding to "||" is the conditional expression. In the conditional statement corresponding to the "? expression", if the reference position is in the true branch, the result corresponding to the conditional expression is obtained; otherwise, the result opposite to the result obtained by the conditional expression is processed. When the judgment statement found is an if statement, the reference position of the array access needs to be calculated.
[0233] After obtaining the conditional expression, different returned results are determined according to the type of the conditional expression. See Figure 11 , Figure 11 which is a schematic diagram of judgment statement processing provided by an embodiment of the present application. As Figure 11 shown, if the conditional statement is the conditional statement corresponding to the "&& expression" or the "|| expression", the conditional statement corresponding to the "&& expression" or the "|| expression" is decomposed into left and right expressions, and the obtained left and right expressions are recursively called the judgment statement processing method to obtain the results returned by the left and right expressions respectively, and the comprehensive result obtained based on the return results of the left and right expressions is returned.
[0234] If the conditional expression is a judgment function of some whitelists, that is, the value of the subscript is between two values to be judged, then directly return LowMax (less than the maximum value) and BigZero (greater than 0). If the conditional expression is a "! expression", the result opposite to the result obtained by the conditional expression needs to be returned, that is, when the result obtained by the conditional expression is LowMax, return BigMax (greater than the maximum value), and when the result obtained by the conditional expression is LowZero (less than zero), return BigZero.
[0235] If the conditional expression is a greater than or less than arithmetic expression, and one of the left and right expressions is equal to the decomposed subscript n, then the corresponding result is returned, where the result is one of the 4 data states of LowMax, BigMax, BigZero, and LowZero.
[0236] To determine whether a parameter is equal to the decomposed subscript n, the adjacent state of the decomposed subscript n in the state list needs to be searched. If there is an expression in the same state as the decomposed subscript n, return the result equal to the expression in the same state.
[0237]
[0238] As shown in the above code, where a is the array name, b is the subscript, c is an expression with the same state as the subscript b, f is the function name, and void is used to indicate that the value returned by the function is null. When processing conditional statements, when it is determined that the expression c is equal to the subscript b, traverse the expressions in the same state as the expression c. If there is an expression c in the same state as the subscript b, that is, the expression c has the same result as the subscript b, return the result equal to the subscript b.
[0239] Among the multiple obtained results, first judge the non-null results. If there are multiple non-null and null results, then further judge the returned non-null results. See Figure 12 , Figure 12 is the first schematic diagram for judging position processing provided by the embodiment of the present application. As Figure 12 shown, there are a total of four judgment statements, and the positions mainly need to be processed according to the four judgment statements respectively. Figure 12 contains the position judgment situations of three of the judgment statements.
[0240] As Figure 12 shown, when the judgment statement contains an && expression, search for the code segment including the array subscript and the array name corresponding to the array subscript in the judgment statement to obtain the reference position of the array access. If the reference position is on the right side of the && expression, use the left expression as the conditional expression corresponding to the reference position, and determine the judgment result corresponding to the conditional expression. When the judgment result is the same as the conditional judgment result LowMax corresponding to the decomposed subscript, determine the state of the decomposed subscript as judged.
[0241] As Figure 12 shown, when the judgment statement contains an || expression, search for the code segment including the array subscript and the array name corresponding to the array subscript in the judgment statement to obtain the reference position of the array access. If the reference position is on the right side of the || expression, use the left expression as the conditional expression corresponding to the reference position, and determine the judgment result corresponding to the conditional expression. When the judgment result is the same as the conditional judgment result BigMax corresponding to the decomposed subscript, determine the state of the decomposed subscript as judged.
[0242] As Figure 12 shown, when the judgment statement contains a? expression, search for the code segment including the array subscript and the array name corresponding to the array subscript in the judgment statement to obtain the reference position of the array access. If the reference position is on the right side of the true expression, use the true expression as the conditional expression corresponding to the reference position, and determine the judgment result corresponding to the conditional expression. When the judgment result is the same as the conditional judgment result LowMax corresponding to the decomposed subscript, determine the state of the decomposed subscript as judged.
[0243] As Figure 12 As shown, when the judgment statement contains a? expression, search for the code segment including the array subscript and the array name corresponding to the array subscript in the judgment statement to obtain the reference position of the array access. If the reference position is on the right side of the false expression, use the false expression as the conditional expression corresponding to the reference position, and determine the judgment result corresponding to the conditional expression. When the judgment result is the same as the result BigMax of the conditional judgment corresponding to the decomposed subscript, determine the state of the decomposed subscript as judged.
[0244] There are three forms in total for other judgment statements. See Figure 13 , Figure 13 which is the second schematic diagram of judgment position processing provided by the embodiments of the present application. As Figure 13 shown, the three forms corresponding to the judgment statement are down, mid, and else respectively. Among them, the position of the down array reference statement is below the influence of the judgment statement, the position of the mid array reference statement is in the middle of the influence of the judgment statement, and the position of the else array reference statement is in the else block of the judgment statement.
[0245]
[0246] As shown in the above code, there are three positions for array access shown in the code. When the reference position of the array access is at the down position of the judgment statement, obtain the judgment result corresponding to the down position, and when it is judged that the code segment corresponding to the down position reassigns the element corresponding to the array subscript in the array, determine the state of the decomposed subscript as judged.
[0247] As Figure 13 shown, when the reference position of the array access is at the mid position of the judgment statement, when the judgment result corresponding to the mid position is the conditional judgment result LowMax corresponding to the decomposed subscript, determine the state of the decomposed subscript as judged.
[0248] As Figure 13 shown, when the reference position of the array access is at the else position of the judgment statement, when the judgment result corresponding to the else position is the conditional judgment result BigMax opposite to the conditional judgment result LowMax corresponding to the decomposed subscript, determine the state of the decomposed subscript as judged.
[0249] If all the decomposed subscripts have returned a judged result, it is considered an overall judged state. If there are subscripts in all the decomposed subscripts that are in an unusual scenario, that is, the subscript has not been judged by the above method, it can also be considered that the overall is in a "judged" state and no warning is required. Otherwise, warning processing needs to be performed on this subscript.
[0250] In summary, the code detection method provided by the embodiments of the present application can improve the accuracy of code detection, correctly identify whether an array access expression is judged, thereby greatly reducing false positives and reducing the processing time of code detection. In addition, code detection can be performed only through a small number of code segments, reducing the implementation difficulty of code detection, and there is no need to calculate the variable status of the array subscript every time an array access is performed, that is, there is no need to calculate the relevant variable status for each step.
[0251] Next, the exemplary structure of the image processing device 555 provided by the embodiments of the present application implemented as a software module will be further described. In some embodiments, as Figure 2 shown, the software module in the image processing device 555 stored in the memory 550 may include:
[0252] The decomposition subscript module 5551 is used to decompose the array subscript in the static code to obtain multiple decomposed subscripts corresponding to the array subscript.
[0253] The judgment scenario module 5552 is used to obtain the judgment statement corresponding to each decomposed subscript from the static code; judge the decomposed subscript based on the first judgment condition corresponding to the judgment statement to obtain the condition judgment result.
[0254] The judgment position module 5553 is used to obtain the reference position of the array corresponding to the array subscript in the judgment statement, and determine the reference position judgment result based on the second judgment condition corresponding to the reference position, where the reference position is the position where the static code accesses the array in the judgment statement.
[0255] The code evaluation module 5554 is used to compare the condition judgment result with the reference position judgment result, and determine the abnormal detection result of the static code according to the comparison result.
[0256] In some embodiments, the code acquisition module 5555 is used to obtain the static code from the code file; when there is a code segment for array access in the static code, obtain the array subscript in the static code from the code segment.
[0257] In some embodiments, the assignment statement processing module 5556 is used to obtain the assignment statement in the static code; when the assignment statement does not include a modulo operation, determine the status of the assigned expression in the assignment statement as the status of the assignment expression in the assignment statement, where the status is an unjudged status or a judged status; when the assigned expression includes an array subscript, determine the status of the array subscript as the status of the assigned expression; when the status of the array subscript is an unjudged status, determine that the operation of decomposing the array subscript in the static code will be executed.
[0258] In some embodiments, the decomposition subscript module 5551 is further configured to iteratively execute the following processes: determine the iteration object for the current iteration, where the iteration object for the first iteration is the array subscript; when the iteration object for the current iteration includes an arithmetic expression, decompose the iteration object for the current iteration based on the arithmetic expression to obtain the decomposition result for the current iteration, and use the decomposition result for the current iteration as the iteration object for the next iteration to continue the iteration; when the iteration object for the current iteration does not include an arithmetic expression, use the iteration object for the current iteration as the decomposition subscript and end the iteration.
[0259] In some embodiments, the scenario filtering module 5557 is configured to obtain the data type of the decomposition subscript; when the data type does not belong to a specific data type, determine that the operation of obtaining the judgment statement corresponding to each decomposition subscript will be executed, where the specific data types include constants, enumerations, array lengths, and macro definitions.
[0260] In some embodiments, the judgment scenario module 5552 is further configured to obtain the first judgment condition of the judgment statement from the static code; when the first judgment condition includes multiple conditional expressions and the multiple conditional expressions are in an AND relationship, judge the decomposition subscript based on the conditional expressions to obtain the judgment result corresponding to each conditional expression, and determine the intersection of the judgment results corresponding to the conditional expressions as the conditional judgment result; when the first judgment condition includes multiple conditional expressions and the multiple conditional expressions are in an OR relationship, judge the decomposition subscript based on the conditional expressions to obtain the judgment result corresponding to each conditional expression, and determine the union of the judgment results corresponding to the conditional expressions as the conditional judgment result; when the first judgment condition includes only one conditional expression, judge the decomposition subscript based on the one conditional expression to obtain the conditional judgment result.
[0261] In some embodiments, the judgment scenario module 5552 is further configured to, when a conditional expression includes a relational operator, determine the position of the decomposition subscript in the conditional expression, and determine the judgment result corresponding to the position as the conditional judgment result; when a conditional expression includes a logical NOT operator, determine the opposite judgment result of the conditional expression as the conditional judgment result; obtain a set of expressions matching the decomposition subscript, where the set of expressions includes a first expression in the same assignment statement as the decomposition subscript and a second expression in the same assignment statement as the first expression; when a conditional expression includes any expression in the set of expressions and the conditional expression does not include the decomposition subscript, determine the judgment result of the conditional expression as the conditional judgment result.
[0262] In some embodiments, the judgment position module 5553 is further configured to, when the judgment statement includes an array subscript and the array name corresponding to the array subscript, determine the position of the array name as the reference position.
[0263] In some embodiments, the position determination module 5553 is further configured to determine the conditional expression as the second determination condition when the jump position corresponding to the execution of the conditional expression in the determination statement matches the reference position; and determine the complement of the conditional expression as the second determination condition when the jump position corresponding to the execution of the conditional expression in the determination statement does not match the reference position.
[0264] In some embodiments, the code evaluation module 5554 is further configured to determine that the exception detection result of the static code is normal when the condition judgment result matches the reference position judgment result; and determine that the exception detection result of the static code is abnormal when the condition judgment result does not match the reference position judgment result.
[0265] In some embodiments, the code evaluation module 5554 is further configured to obtain the exception detection results corresponding to each decomposed subscript; and output an alarm message when any of the exception detection results is abnormal, where the alarm message is used to indicate that there is an array out-of-bounds exception in the static code.
[0266] An embodiment of the present application provides a computer program product, which includes computer-executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer-executable instructions from the computer-readable storage medium, and the processor executes the computer-executable instructions, so that the electronic device executes the code detection method described above in the embodiments of the present application.
[0267] An embodiment of the present application provides a computer-readable storage medium storing computer-executable instructions, where computer-executable instructions or a computer program are stored. When the computer-executable instructions or the computer program are executed by a processor, it will cause the processor to execute the code detection method provided in the embodiments of the present application. For example, Figures 3A to 3J the code detection method shown.
[0268] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disc, or CD-ROM; or may be various devices including one or any combination of the above memories.
[0269] In some embodiments, the computer-executable instructions may be in the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including being deployed as an independent program or being deployed as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0270] By way of example, the computer-executable instructions may or may not correspond to files in a file system, and may be stored as part of a file that holds other programs or data. For example, they may be stored in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple cooperating files (such as files that store one or more modules, subroutines, or portions of code).
[0271] By way of example, the computer-executable instructions may be deployed to execute on one electronic device, or on multiple electronic devices located at one location, or on multiple electronic devices distributed across multiple locations and interconnected via a communication network.
[0272] In summary, through the embodiments of the present application, multiple decomposed subscripts are obtained by decomposing the array subscripts in the static code, without the need to calculate the overall state of the array subscripts, improving the efficiency of code detection. The judgment statements corresponding to each decomposed subscript are obtained, and the decomposed subscripts are judged based on the first judgment conditions corresponding to the judgment statements to obtain the conditional judgment results. Then, based on the second judgment conditions corresponding to the reference positions of the arrays corresponding to the array subscripts, the reference position judgment results are determined. According to the comparison result of the conditional judgment result and the reference position judgment result, the abnormal detection result of the static code is determined. Thus, it is possible to avoid determining the numerical range corresponding to the array subscript when accessing the array through a large amount of calculation, and only perform code detection through a small number of code segments, reducing the implementation difficulty of code detection and further improving the accuracy of code detection.
[0273] The above is only an example of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent replacements, and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.< / c>
Claims
1. A code detection method, characterized in that, The method includes: Decompose the array subscript in the static code to obtain multiple decomposed subscripts corresponding to the array subscript; Obtain, from the static code, a judgment statement corresponding to each of the decomposed subscripts; Judge the decomposed subscript based on a first judgment condition corresponding to the judgment statement to obtain a condition judgment result; Obtain a reference position of the array corresponding to the array subscript in the judgment statement, and determine a reference position judgment result based on a second judgment condition corresponding to the reference position, where the reference position is a position where the static code accesses the array in the judgment statement; Compare the condition judgment result with the reference position judgment result, and determine an exception detection result of the static code according to the comparison result.
2. The method according to claim 1, wherein Before decomposing the array subscript in the static code, the method further includes: Obtain the static code from a code file; When there is a code segment for array access in the static code, obtain the array subscript in the static code from the code segment.
3. The method according to claim 2, wherein After obtaining the array subscript in the static code from the code segment, the method further includes: Obtain an assignment statement in the static code; When the assignment statement does not include a modulo operation, determine the status of the assigned expression in the assignment statement as the status of the assignment expression in the assignment statement, where the status is an unjudged status or a judged status; When the assigned expression includes the array subscript, determine the status of the array subscript as the status of the assigned expression; When the status of the array subscript is the unjudged status, determine that the operation of decomposing the array subscript in the static code will be executed.
4. The method according to claim 1, characterized in that Decomposing the array subscript in the static code to obtain multiple decomposed subscripts corresponding to the array subscript includes: Iteratively execute the following processing: Determine an iteration object for the current iteration, where the iteration object for the first iteration is the array subscript; When the iteration object for the current iteration includes an arithmetic expression, decompose the iteration object for the current iteration based on the arithmetic expression to obtain a decomposition result for the current iteration, and use the decomposition result for the current iteration as the iteration object for the next iteration to continue the iteration; When the iteration object for the current iteration does not include an arithmetic expression, use the iteration object for the current iteration as the decomposed subscript and end the iteration.
5. The method according to claim 1, wherein Before obtaining the judgment statement corresponding to each of the decomposed subscripts, the method further includes: Obtain the data type of the decomposed subscript; When the data type does not belong to a specific data type, determine that the operation of obtaining the judgment statement corresponding to each of the decomposed subscripts will be executed, where the specific data types include constants, enumerations, array lengths, and macro definitions.
6. The method according to claim 1, wherein Judging the decomposed subscript based on a first judgment condition corresponding to the judgment statement to obtain a condition judgment result includes: Obtain the first judgment condition of the judgment statement from the static code; When multiple conditional expressions are included in the first judgment condition and the multiple conditional expressions are in an AND relationship, the decomposed subscript is judged based on the conditional expressions to obtain a judgment result corresponding to each conditional expression, and the intersection of the judgment results corresponding to the conditional expressions is determined as the conditional judgment result; When multiple conditional expressions are included in the first judgment condition and the multiple conditional expressions are in an OR relationship, the decomposed subscript is judged based on the conditional expressions to obtain a judgment result corresponding to each conditional expression, and the union of the judgment results corresponding to the conditional expressions is determined as the conditional judgment result; When only one conditional expression is included in the first judgment condition, the decomposed subscript is judged based on the one conditional expression to obtain the conditional judgment result.
7. The method according to claim 6, wherein The judging the decomposed subscript based on the one conditional expression to obtain the conditional judgment result includes: When the one conditional expression contains a relational operator, determine the position of the decomposed subscript in the conditional expression, and determine the judgment result corresponding to the position as the conditional judgment result; When the one conditional expression contains a logical NOT operator, determine the opposite judgment result of the conditional expression as the conditional judgment result; Obtain an expression set matching the decomposed subscript, where the expression set includes a first expression in the same assignment statement as the decomposed subscript and a second expression in the same assignment statement as the first expression; When the one conditional expression contains any expression in the expression set and the one conditional expression does not contain the decomposed subscript, determine the judgment result of the conditional expression as the conditional judgment result.
8. The method according to claim 1, wherein The obtaining the reference position of the array corresponding to the array subscript in the judgment statement includes: When the judgment statement contains the array subscript and the array name corresponding to the array subscript, determine the position of the array name as the reference position.
9. The method according to claim 1, wherein Before determining the reference position judgment result based on the second judgment condition corresponding to the reference position, the method further includes: When the jump position corresponding to the conditional expression in the judgment statement matches the reference position, determine the conditional expression as the second judgment condition; When the jump position corresponding to the conditional expression in the judgment statement does not match the reference position, determine the complement of the conditional expression as the second judgment condition.
10. The method according to claim 1, wherein The comparing the conditional judgment result with the reference position judgment result and determining the abnormal detection result of the static code according to the comparison result includes: When the conditional judgment result matches the reference position judgment result, determine the abnormal detection result of the static code as normal; When the conditional judgment result does not match the reference position judgment result, determine the abnormal detection result of the static code as abnormal.
11. The method according to claim 1, wherein After comparing the condition judgment result with the reference position judgment result and determining the exception detection result of the static code according to the comparison result, the method further includes: Obtaining the exception detection results corresponding to each of the decomposed subscripts; When any of the exception detection results is an exception, outputting an alarm message, where the alarm message is used to indicate that there is an array out-of-bounds exception in the static code.
12. A code detection device, characterized in that, The test device includes: A decomposed subscript module, configured to decompose the array subscript in the static code to obtain a plurality of decomposed subscripts corresponding to the array subscript; A judgment scenario module, configured to obtain, from the static code, a judgment statement corresponding to each of the decomposed subscripts; and judge the decomposed subscript based on a first judgment condition corresponding to the judgment statement to obtain a condition judgment result; A judgment position module, configured to obtain a reference position of the array corresponding to the array subscript in the judgment statement, and determine a reference position judgment result based on a second judgment condition corresponding to the reference position, where the reference position is a position where the static code accesses the array in the judgment statement; A code evaluation module, configured to compare the condition judgment result with the reference position judgment result, and determine the exception detection result of the static code according to the comparison result.
13. An electronic device, characterized in that, The electronic device includes: A memory, configured to store computer-executable instructions; A processor, configured to implement the code detection method according to any one of claims 1 to 11 when executing the computer-executable instructions or computer program stored in the memory.
14. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that, The computer-executable instructions or computer program, when executed by the processor, implement the code detection method according to any one of claims 1 to 11.
15. A computer program product, comprising computer-executable instructions or a computer program, characterized in that, The computer-executable instructions or computer program, when executed by the processor, implement the code detection method according to any one of claims 1 to 11.