Code Scanning Method, Device, Computing Device and Computer Storage Medium

Through the method of extracting, analyzing and detecting code information, marking and positioning code problems, the problem that the existing technology cannot discover and locate before code execution problems in a timely manner, realize the discovery and positioning of before code execution problems, and improve the efficiency of code correction.

CN112527623BActive Publication Date: 2025-05-27BEIJING QIHOOD TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN201910889415.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-09-19
Publication Date
2025-05-27
Estimated Expiration
2039-09-19

AI Technical Summary

Technical Problem

Existing code scanning tools cannot promptly discover and locate problems that have not been detected before code execution, such as failure to execute code, no alarm mechanism, unjudgment of resources, and unstable data, resulting in errors during code execution.

Method used

Provide a code scanning method, including scanning code files, extracting code information, analyzing and sorting code information, detecting whether there are problems in the code information, and marking and locating code problems.

Benefits of technology

Through the code scanning method, code problems can be discovered and located before execution on the code line, effectively solving possible errors during code execution, and improving the efficiency of code correction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112527623B_ABST
    Figure CN112527623B_ABST
Patent Text Reader

Abstract

The present invention discloses a code scanning method, apparatus, computing device, and computer storage medium. The method includes: scanning a code file to extract code information of the code file; analyzing and organizing the code information and caching the code information by classification; detecting the cached code information to determine whether there are code problems in the code information; if so, marking and locating the code problems. By scanning the code file, code problems existing in the code can be discovered before the code is executed online, effectively locating and marking the code problems, facilitating the correction of the code file, and solving the existing code problems.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of code security, and particularly to a code scanning method and apparatus. Background Art

[0002] For the code executed online, there are problems such as no alarm mechanism when the code execution fails, no necessary judgment on the required resources before the code execution, and the data relied on by the code is not the latest data. If these problems are not detected before the code execution, it will cause the code to report an error during the execution process.

[0003] Although the prior art can use a code scanning tool to scan the code, for the above non-code logic problems, the existing code scanning tools cannot detect and locate the problems in time. Summary of the Invention

[0004] In view of the above problems, the present invention is proposed to provide a code scanning method, apparatus, computing device, and computer storage medium that overcome the above problems or at least partially solve the above problems.

[0005] According to one aspect of the present invention, there is provided a code scanning method, which includes:

[0006] Scanning a code file and extracting code information of the code file;

[0007] Analyzing and organizing the code information, and classifying and caching the code information;

[0008] Detecting the cached code information to determine whether there are code problems in the code information;

[0009] If so, marking and locating the code problems.

[0010] According to another aspect of the present invention, there is provided a code scanning apparatus, which includes:

[0011] A scanning module adapted to scan a code file and extract code information of the code file;

[0012] A caching module adapted to analyze and organize the code information, and classify and cache the code information;

[0013] A detecting module adapted to detect the cached code information to determine whether there are code problems in the code information;

[0014] A marking and locating module adapted to mark and locate the code problems if the detecting module determines that there are code problems in the code information.

[0015] According to another aspect of the present invention, there is provided a computing device, comprising: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus;

[0016] The memory is used for storing at least one executable instruction, and the executable instruction causes the processor to perform operations corresponding to the above code scanning method.

[0017] According to another aspect of the present invention, there is provided a computer storage medium, in which at least one executable instruction is stored, and the executable instruction causes the processor to perform operations corresponding to the above code scanning method.

[0018] According to still another aspect of the present invention, there is provided a computing device, comprising: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus;

[0019] The memory is used for storing at least one executable instruction, and the executable instruction causes the processor to perform operations corresponding to the above code scanning method.

[0020] According to yet another aspect of the present invention, there is provided a computer storage medium, in which at least one executable instruction is stored, and the executable instruction causes the processor to perform operations corresponding to the above code scanning method.

[0021] According to the code scanning method, device, computing device, and computer storage medium provided by the present invention, a code file is scanned to extract code information of the code file; the code information is analyzed and sorted, and the code information is classified and cached; the cached code information is detected to determine whether there is a code problem in the code information; if so, the code problem is marked and located. By scanning the code file, code problems existing in the code can be found before the code is executed on the code line, effectively locating and marking the code problems, facilitating the correction of the code file, and solving the existing code problems.

[0022] The above description is only an overview of the technical solution of the present invention. In order to be able to understand the technical means of the present invention more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features, and advantages of the present invention more obvious and understandable, the following specific embodiments of the present invention are specifically given. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] By reading the following detailed description of the preferred embodiments, various other advantages and benefits will become clear to those of ordinary skill in the art. The drawings are only for the purpose of showing the preferred embodiments and are not considered to be a limitation of the present invention. And throughout the drawings, the same reference numerals are used to represent the same components. In the drawings:

[0024] Figure 1 Shows a schematic flowchart of a code scanning method according to an embodiment of the present invention;

[0025] Figure 2 Shows a schematic diagram of the code information storage method;

[0026] Figure 3 Shows a schematic flowchart of a code scanning method according to another embodiment of the present invention;

[0027] Figure 4 Shows a schematic diagram of the code information storage method of the code file and other referenced code files;

[0028] Figure 5 Shows a block diagram of the structure of a code scanning device according to an embodiment of the present invention;

[0029] Figure 6 Shows a schematic diagram of the structure of a computing device according to an embodiment of the present invention. Detailed implementation manners

[0030] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided so that the present disclosure can be more thoroughly understood and the scope of the present disclosure can be completely conveyed to those skilled in the art.

[0031] Figure 1 Shows a schematic flowchart of a code scanning method according to an embodiment of the present invention, as Figure 1 shown, the method includes the following steps:

[0032] Step S101, scan the code file and extract the code information of the code file.

[0033] Obtain the code file, such as the test.sh file, and scan the test.sh file. When scanning, it can be scanned line by line at a time, obtaining one line of content of the code file at a time, or it can be scanned multiple lines at a time, obtaining multiple lines of content of the code file at a time. After obtaining one or more lines of content of the code file, it can be cached in the memory first, and then the entire cached code file or a certain section of the cached code file (a certain function in the code file, a certain section of declaration code, etc.) can be analyzed, extracted, etc. to obtain the code information in the code file. Here, the code information includes variables, parameters, functions, etc.

[0034] Variables need to be declared in the code to store data, information, etc. Variables are classified into numerical variables, date variables, character variables, etc. according to different declared types, and are classified into global variables, variables within functions, etc. according to their declared positions. The extraction of variables can be achieved by parsing the variable declaration code in the code file to extract the corresponding variables.

[0035] Parameters are the arguments that need to be passed when a function is called. According to the code during function declaration, the included parameters, etc. are extracted. The parameter declaration during function declaration also includes the declaration of parameter types. Based on the declaration of parameter types, the corresponding types of parameters can be determined.

[0036] Extract the corresponding function name from the code file according to the function declaration, and the starting line number information of function initialization, the function implementation function information, etc. can also be extracted according to the code file.

[0037] Step S102, analyze and organize the code information, and classify and cache the code information.

[0038] After extracting the code information, analyze and organize variables, parameters, functions, etc. in the code information respectively, and cache them classified for variables, parameters, functions, etc. Specifically, different stacks can be used to cache variables, parameters, functions, etc. respectively.

[0039] For variables, it is necessary to first organize the variables in the code information. For example, variable a = 20190801 is extracted from the code file, where the variable is a. When the code file declares a, it also assigns a value to it, and the assignment information is 20190801. Store the variable and the corresponding assignment information in the form of key-value pairs. In the key-value pair, the key value is a, and the corresponding value value is 20190801. In the code file, variables include global variables (used by multiple functions in the code file), variables used in a single function, etc. For different variables, they need to be stored separately. For example, for global variables, organize the global variables in the code information and store the global variables and the corresponding assignment information in the form of key-value pairs. When storing, since global variables can be used by multiple functions in the code file and are not limited to a certain function, the global variables are associated with the code file, and a code file binds and stores the key-value pairs of all global variables and the corresponding assignment information in the code file. For variables in a single function, divide a single function from the code information, and store the variables and the corresponding assignment information in the code information of at least one function in the form of key-value pairs bound to the function name. For example, separate storage spaces are allocated for each function declared in the code file, and under the storage space of each function, store the key-value pairs of the variables of the function and the corresponding assignment information.

[0040] Furthermore, for the variables in a function, some variables are only assigned a value once and then used, while some variables are assigned values multiple times. For command statements such as case, while, for, if, etc., they will cause variables to be assigned values multiple times. To detect each assignment of a variable subsequently, it is also necessary to parse the traversal statements of at least one function in the code information (such as command statements like case, while, for, if, etc.), and bind and store the variables in the traversal statements and the corresponding assignment information for each traversal in the form of key-value pairs with the function name. For example, for the variable i which is assigned values multiple times, and the assignment information is 1, 2, 3..., during storage, the assignment information for each time the variable is re-assigned after each traversal is stored, that is, multiple key-value pairs are stored. The key value of each key-value pair is i, and the value value is the assignment information for each traversal.

[0041] Furthermore, if the assignment information also contains reference relationships to other variables and parameters, such as b = / home / test / $a. Among them, the assignment information of variable b also references variable a. When the existing scanning tool scans variable b, since variable b references variable a, it cannot directly perform problem scanning on variable b like this and often ignores the detection of variable b. In this embodiment, if the assignment information of a variable also contains reference relationships to other variables and parameters, the assignment information of the variable is parsed, and the other variables and parameters being referenced are replaced with the corresponding assignment information of the other variables and parameters according to the reference relationship. For example, if variable b references variable a, the assignment information of variable b is parsed, and according to the reference relationship, the other variable a being referenced is replaced with the corresponding assignment information of other variable a, and the assignment information of variable b after replacement is obtained as b = / home / test / 20190801. For the assignment information that contains reference relationships to other variables and parameters, after extracting the variables in the code information, the variables and the assignment information after replacement are stored in the form of key-value pairs, and the stored assignment information is the direct assignment information when the variable is used, which is convenient for subsequent direct detection of the variable and the assignment information and ensures the detection accuracy.

[0042] For parameters, when storing them in a classified manner, at least one parameter in at least one function in the code information needs to be stored bound to the function name according to its call order. First, after determining the function name, record each parameter referenced by the function, and then, according to the actual call order of each parameter in the function, bind and store the parameters to the function name in sequence. For example, if the parameters $1 and $2 are referenced in a function, and $2 is called first in the function and then $1, according to the actual call order, store the parameter $2 first and then store the parameter $1. When storing, a first-in, first-out data storage structure can be used to store according to the call order. Further, the assignment information of the parameters is generally passed in when the function is called. Using only existing scanning tools, it is impossible to determine the assignment information of the parameters and perform a scanning detection on the parameters. In this embodiment, by analyzing the context relationship of the code file, extract the assignment information of the parameters passed in when the function is called, and bind and store the parameters and the corresponding assignment information in the form of key-value pairs to the function name, which can facilitate the subsequent detection of the assignment information of the parameters. If the assignment information of a variable contains a reference relationship to a parameter, after obtaining the assignment information of the parameter, the referenced parameter can be replaced with the assignment information corresponding to the parameter according to the reference relationship to obtain the assignment information after variable replacement. For example, if the variable c = $1, when the function is called, the parameter $1 is passed in with the assignment information test. After binding and storing the parameter $1 and the assignment information test in the form of key-value pairs to the function name, it is also necessary to replace the assignment information of the variable c to obtain the assignment information of the variable c and its replacement test for storage.

[0043] For functions, based on the extracted code information, the starting line number information of at least one function can be located to obtain the starting line number information of the function, and the ending line number information of the function can also be obtained at the same time, etc. For functions, it is also necessary to obtain the function's function information to facilitate the detection of the function's implemented function information, etc. Bind the obtained starting line number information of the function, the function's function information, etc. to the corresponding function name.

[0044] When storing, it can be in the form as Figure 2 shown in the storage method, divide the corresponding storage space for a code file, store the code information of all global variables corresponding to the code file, and divide the corresponding storage space for each function included in the code file. The storage space of each function stores the code information such as variables, parameters, and function's function information included in the function.

[0045] Step S103, detect the cached code information to determine whether there are code problems in the code information.

[0046] After caching each code information, detection can be performed based on the cached code information.

[0047] Specifically, detect the cached variables, parameters, and their corresponding assignment information: Detect whether the variables and parameters are declared before being referenced (it is possible to detect whether they are declared when extracting code information such as variables and parameters, and they have not been referenced when declared, or after caching, confirm whether the declaration positions of the variables, parameters, etc. in the code file are earlier than their reference positions, etc.). If not, it is determined that there is a code problem in the code information; Detect whether the variables and parameters are assigned values before being referenced (detect whether there is corresponding assignment information for variables, parameters, etc., and detect whether their assignment operations in the code file are before the reference, etc.). If not, it is determined that there is a code problem in the code information; Whether the assignment information of the variables and parameters conforms to the declaration information of the variables and parameters (detect whether it conforms to the declaration information of the variables and parameters according to the cached assignment information of the variables and parameters; when a variable is assigned multiple times, it is necessary to detect whether the assignment information of each assignment conforms to its declaration information). If not, it is determined that there is a code problem in the code information.

[0048] Perform functional verification and detection on the function functions related to the cached functions. If the function function is a function that can be executed in parallel, it is necessary to detect whether the function implements the function corresponding to the function information. The function information includes functions such as parallel execution, error feedback, alarm, file existence verification, etc. For example, according to the cached function information of the function, detect whether the code file contains the code that implements the function information. If not, it is determined that there is a code problem in the code information.

[0049] Step S104, mark and locate the code problem.

[0050] After detecting the code problem, the corresponding code problem location information can also be determined according to the code problem, so that the user can correct the code problem according to the location information. This step can be executed when any code problem is detected in step S103 to directly locate the detected code problem, or it can be executed after step S103 is detected to locate the detected code problems respectively. There is no limit here.

[0051] When locating the code problem, if the code problem is a problem of a global variable, it can be located to the specific global variable cached in the code file, and it can also be located to the specific location information (declaration position information, reference position information, etc. in the code file) where the global variable has a code problem in the code file. If the code problem is a variable, parameter, etc. in a function, it can be located to the specific variables and parameters cached by the function in the code file, or it can be located to the specific location information where the variable or parameter has a code problem in the code file. If the code problem is the function information of a function, it is located to the function name cached in the code file, or the location information of the function in the code file, etc.

[0052] The positioning code problem can store the positioned and cached code information together, or store the code problem and the corresponding code problem positioning information in the code problem database for unified management.

[0053] According to the code scanning method provided by the present invention, scan the code file to extract the code information of the code file; analyze and sort out the code information, and classify and cache the code information; detect the cached code information to determine whether there is a code problem in the code information; if so, mark and locate the code problem. By scanning the code file, code problems existing in the code can be found before the code is executed online, effectively locate and mark the code problems, which is convenient for correcting the code file and solving the existing code problems.

[0054] Figure 3 The flowchart of the code scanning method according to another embodiment of the present invention is shown, as Figure 3 shown, the method includes the following steps:

[0055] Step S301, perform code logic detection on the code file to determine whether there is a code problem in the code file.

[0056] During the process of scanning the code file, perform code logic detection on the code file. The code logic detection includes, for example, determining whether the existence of input information is monitored before the task (such as a streaming task) in the code file is started. If not, it is determined that there is a code problem in the code file; determining whether a retry mechanism is set for the task in the code file. If not, it is determined that there is a code problem in the code file; determining whether a notification mechanism is set for the failure of the task in the code file. If not, it is determined that there is a code problem in the code file; determining the real-time nature of the input file. If no judgment is made, it is determined that there is a code problem in the code file; determining whether there is an insecure copy. If so, it is determined that there is a code problem in the code file; determining whether the copy is a cross-machine copy. If so, it is determined that there is a code problem in the code file; determining whether the account used for the copy is a public account. If not, it is determined that there is a code problem in the code file; determining whether the recipients in the email notification are not updated (there are, for example, former employees, non-designated personnel, etc. among the recipients). If not updated, it is determined that there is a code problem in the code file, etc. The code logic detection is set based on the actual situation of the code file. Here, it is for illustrative purposes and is not specifically limited.

[0057] This step is executed during the process of scanning the code file, and it can be executed together with step S302.

[0058] Further, if, during the process of scanning a code file, step S302 determines that the code file references at least one other code file, then the code logic detection of the code file includes the code logic detection of the code file and the referenced other code files. When a code file is scanned, code logic detection is performed on the code file. When a referenced other code file is scanned, code logic detection is performed on the referenced other code file.

[0059] When scanning a code file or a referenced other code file, if it is determined that there is a code problem in the code file or the referenced other code file after code logic detection, the code problem is recorded to facilitate subsequent marking and positioning of the code problem. The code problem detected by code logic is located in a specific code file or the referenced other code file.

[0060] Step S302: Determine whether the code file references at least one other code file.

[0061] Depending on the different functions implemented by the code file, it sometimes needs to reference other code files. During the process of scanning a code file, by reading the specific content of the code file, it can be determined whether it references other code files. For example, during the process of scanning the code file test.sh, it is read that test.sh contains a command statement that references the conf.sh code file or a function call statement (the function is a function in the conf.sh code file), and it can be determined that the code file test.sh references the code file conf.sh.

[0062] A code file may reference one or more other code files. During the process of scanning the code file, the other code files referenced by the code file are determined based on the command statements in the code file that reference other code files or the function call statements that call functions not in this code file and the information of the code file where the function is located.

[0063] If the code file references other code files, then during scanning, in addition to scanning the code file as in Figure 1 the embodiment, it is also necessary to scan the other code files referenced by the code file. If it is determined that the code file does not reference other code files, it can be executed according to the Figure 1 steps described in the embodiment, which will not be elaborated here. If it is determined that the code file references at least one other code file, then step S303 is executed.

[0064] Step S303: Scan the code file and at least one other code file, extract the code information of the code file and the at least one other code file, and record the reference relationship between the code file and the at least one other code file in a tree structure.

[0065] During the process of scanning a code file, when it is determined that the code file references at least one other code file, the current scan of the code file can be temporarily saved first, the scan position is recorded, and the scan jumps to the other referenced code file. The other referenced code file is scanned preferentially, and the code information of the other code file is extracted from it. After the scan of the other referenced code file is completed, the code file is scanned continuously from the recorded scan position of the code file, and the code information of the code file is extracted.

[0066] Among them, the code information of the code file and the code information of the other code file are respectively bound and stored with their respective code files, and the reference relationship between the code file and the other code file is associated and recorded in a tree structure. Specifically, as Figure 4 shown, if the code file references other code file 1, other code file 2..., and other code file 1 references other code file 3, according to the reference relationship, the code file and at least one other code file are associated using a tree structure. The code information of the code file and the code information of the other code file obtained by scanning the code file and the other code file are respectively bound and stored with their respective code files.

[0067] Step S304: Analyze and organize the code information, and classify and cache the code information.

[0068] The code information of the scanned code file and the code information of the other code file are respectively analyzed and organized, and classified and cached. Specifically, as Figure 4 shown, corresponding storage spaces are allocated for the code file to store the code information corresponding to the code file, and storage spaces are allocated for other code file 1, 2, 3... etc. to store their respective corresponding code information. The reference relationship between the code file and other code file 1, 2, 3... is associated through a tree structure.

[0069] For the specific storage of the code information, refer to Figure 1 the description of step S102 in the embodiment, which will not be elaborated here.

[0070] Step S305: Detect the cached code information to determine whether there are code problems in the code information.

[0071] The code information of the cached code file and the code information of the other code file are detected to determine whether there are code problems in the code file and the other code file.

[0072] For the detection of the cached code information, refer to Figure 1 the description of step S103 in the embodiment, which will not be elaborated here.

[0073] Step S306: Mark and locate the code problems.

[0074] When marking and locating code problems, for the code problems existing between the code files determined by code logic detection, locate to the code files and other code files. For the code problems existing in the code information determined by detecting code information, locate to the code information or the specific location information of the code information in the code file or other code files.

[0075] Step S307: Obtain code problems from the code problem database and display them on the code problem display page.

[0076] To facilitate the user to intuitively view the code problems of the code file or the code problems in other referenced code files, this embodiment also provides a code problem display page, which can obtain the stored code problems from the code problem database and display the code problems and code problem location information, etc. on the code problem display page. The specific display method can use, for example, a table, etc., which is not limited here.

[0077] According to the code scanning method provided by the present invention, both the code file and other code files referenced by the code file can be scanned, and the code information of the scanned code file and the code information of other code files are associated and stored using a tree structure. On the one hand, the scanning of the code file and other code files referenced by the code file can be completed at one time. On the other hand, according to the reference relationship between code files, the assignment information of parameter calls between code files can be obtained, so that the assignment information of parameters can be detected. Compared with existing scanning tools, the detection is more comprehensive and accurate, and it solves the problem that existing scanning tools cannot detect code problems that are not code logic. Further, the present invention also provides a code problem display page to display the code problems to the user, and the user can directly correct the code file according to the displayed code problems and code problem location information, improving the efficiency of the user to correct code problems.

[0078] Figure 5 Shows the structural block diagram of a code scanning device according to an embodiment of the present invention, as Figure 5 shown, the device includes:

[0079] The scanning module 510 is adapted to: scan the code file and extract the code information of the code file.

[0080] The cache module 520 is adapted to: analyze and organize the code information and classify and cache the code information.

[0081] The detection module 530 is adapted to: detect the cached code information and determine whether there are code problems in the code information.

[0082] The marker positioning module 540 is adapted to: if the detection module 530 determines that there is a code problem in the code information, mark and position the code problem.

[0083] Optionally, the scanning module 510 is further adapted to: determine whether at least one other code file is referenced in the code file; if so, scan the code file and at least one other code file, extract the code information of the code file and at least one other code file, and associate and record the reference relationship between the code file and at least one other code file in a tree structure.

[0084] Optionally, the caching module 520 further includes: a variable unit 521, a function unit 522, and a parameter unit 523.

[0085] The variable unit 521 is adapted to: sort out the variables in the code information and store the variables and the corresponding assignment information in a key-value pair manner.

[0086] The function unit 522 is adapted to: locate the starting line number information and / or function information of at least one function in the code information and bind it to the corresponding function name.

[0087] The parameter unit 523 is adapted to: store at least one parameter in at least one function in the code information bound to the function name in the order of its call.

[0088] Optionally, the variable unit 521 is further adapted to: sort out the global variables in the code information and store the global variables and the corresponding assignment information in a key-value pair manner; and / or, store the variables and the corresponding assignment information in at least one function in the code information bound to the function name in a key-value pair manner; and / or, parse the traversal statements of at least one function in the code information, and store the variables in the traversal statements and the corresponding assignment information in a key-value pair manner bound to the function name for each traversal.

[0089] Optionally, the parameter unit 523 is further adapted to: extract the assignment information of the parameters passed in when the function is called, and store the parameters and the corresponding assignment information bound to the function name in a key-value pair manner.

[0090] Optionally, the variable unit 521 is further adapted to: parse the assignment information, replace the referenced other variables and / or parameters with the assignment information corresponding to the other variables and / or parameters according to the reference relationship; sort out the variables in the code information, and store the variables and the replaced assignment information in a key-value pair manner.

[0091] Optionally, the detection module 530 further includes: a variable parameter detection unit 531 and a function detection unit 532.

[0092] The variable parameter detection unit 531 is adapted to: detect the cached variables and / or parameters and their corresponding assignment information, and determine whether there are code problems with the variables and / or parameters; wherein, the detection includes one or more of the following: whether the variables and / or parameters are declared before being referenced; whether the variables and / or parameters are assigned before being referenced; whether the assignment information of the variables and / or parameters conforms to the declaration information of the variables and / or parameters.

[0093] The function detection unit 532 is adapted to: perform function verification detection according to the cached function information, and determine whether the code information implements the function corresponding to the function information; wherein, the function information includes: parallel execution, error feedback, alarm, and / or file existence verification.

[0094] Optionally, the apparatus further includes: a code logic detection module 550.

[0095] The code logic detection module 550 is adapted to: perform code logic detection on the code file when scanning the code file, and determine whether there are code problems in the code file; wherein, the code logic detection includes one or more of the following: determining whether the existence of input information is monitored before the task starts, determining whether a retry mechanism is set for the task, determining whether a notification mechanism is set for task failure, determining the timeliness of the input file, determining whether there is an insecure copy and / or cross-machine copy, determining whether the account used for copying is a public account, and determining whether the recipients in the email notification are updated in a timely manner.

[0096] Optionally, the marking and positioning module 540 is further adapted to: determine the corresponding code problem positioning information according to the code problem; store the code problem and the corresponding code problem positioning information in the code problem database.

[0097] Optionally, the apparatus further includes: a display module 560.

[0098] The display module 560 is adapted to: obtain the code problems from the code problem database and display them on the code problem display page.

[0099] The descriptions of the above modules refer to the corresponding descriptions in the method embodiments and will not be elaborated here.

[0100] The present invention also provides a non-volatile computer storage medium, and the computer storage medium stores at least one executable instruction, and the executable instruction can execute the code scanning method in any of the above method embodiments.

[0101] Figure 6 The structural schematic diagram of a computing device according to an embodiment of the present invention is shown, and the specific implementation of the computing device in the specific embodiments of the present invention is not limited.

[0102] As Figure 6As shown in the figure, the computing device may include: a processor 602, a communications interface 604, a memory 606, and a communication bus 608.

[0103] Wherein:

[0104] The processor 602, the communications interface 604, and the memory 606 communicate with each other via the communication bus 608.

[0105] The communications interface 604 is used to communicate with network elements of other devices such as clients or other servers.

[0106] The processor 602 is used to execute the program 610, and specifically can execute the relevant steps in the above-mentioned code scanning method embodiments.

[0107] Specifically, the program 610 may include program code, and the program code includes computer operation instructions.

[0108] The processor 602 may be a central processing unit (CPU), or a specific integrated circuit (ASIC) (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention. One or more processors included in the computing device may be of the same type of processor, such as one or more CPUs; or may be of different types of processors, such as one or more CPUs and one or more ASICs.

[0109] The memory 606 is used to store the program 610. The memory 606 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk memory.

[0110] The program 610 is specifically used to cause the processor 602 to execute the code scanning method in any of the above method embodiments. For the specific implementation of each step in the program 610, reference may be made to the corresponding steps and descriptions in the corresponding units in the above code scanning embodiments, which will not be elaborated here. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding process descriptions in the foregoing method embodiments, which will not be elaborated here.

[0111] The algorithms and displays provided herein are not inherently related to any particular computer, virtual system, or other apparatus. Various general-purpose systems can also be used in conjunction with the teachings based hereon. The structure required to construct such systems will be apparent from the above description. In addition, the present invention is not directed to any particular programming language. It should be appreciated that the teachings of the present invention can be implemented in various programming languages, and the description of specific languages above is for the purpose of disclosing the best mode of the present invention.

[0112] In the specification provided herein, numerous specific details are set forth. However, it can be understood that embodiments of the present invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.

[0113] Similarly, it should be understood that in order to streamline this disclosure and assist in understanding one or more of the various inventive aspects, in the foregoing description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together in a single embodiment, figure, or description thereof. However, the disclosed method should not be construed as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim. Rather, as the following claims reflect, the inventive aspects lie in less than all of the features of the preceding disclosed single embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of the present invention.

[0114] Those skilled in the art will appreciate that the modules in the devices in the embodiments can be adaptively changed and disposed in one or more devices different from the embodiments. The modules or units or components in the embodiments can be combined into one module or unit or component, and in addition, they can be divided into multiple sub-modules or sub-units or sub-components. Except that at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all the features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all the processes or units of any method or device so disclosed. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) can be replaced by an alternative feature providing the same, equivalent, or similar purpose.

[0115] In addition, those skilled in the art will understand that although some embodiments described herein include certain features included in other embodiments rather than other features, the combination of features of different embodiments means that it is within the scope of the present invention and forms different embodiments. For example, in the following claims, any of the claimed embodiments can be used in any combination.

[0116] Each component embodiment of the present invention can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art should understand that a microprocessor or a digital signal processor (DSP) can be used in practice to implement some or all of the functions of some or all of the components according to the embodiments of the present invention. The present invention can also be implemented as a device or apparatus program (for example, a computer program and a computer program product) for executing part or all of the methods described herein. Such a program for implementing the present invention can be stored on a computer-readable medium, or can be in the form of one or more signals. Such signals can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

[0117] It should be noted that the above embodiments illustrate the present invention rather than limit the present invention, and those skilled in the art can design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in the claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention can be implemented by means of hardware including several different elements and by means of a suitably programmed computer. In the unit claims listing several devices, several of these devices can be embodied by the same item of hardware. The use of the words first, second, and third, etc. does not denote any order. These words can be interpreted as names.

Claims

1. A code scanning method, which includes: Scanning a code file to extract code information of the code file, where the code information includes variables, parameters, and / or functions; Analyzing and organizing the code information, and classifying and caching the code information; Detecting the cached code information to determine whether there are code problems in the code information; If so, marking and locating the code problems; The analyzing and organizing the code information, and classifying and caching the code information further includes: Organizing the variables in the code information, and storing the variables and the corresponding assignment information in a key-value pair manner; And / or, Locating the starting line number information and / or function information of at least one function in the code information, and binding it to the corresponding function name; And / or, Storing at least one parameter in at least one function in the code information in the order of its call and binding it to the function name.

2. The method according to claim 1, wherein, The scanning the code file to extract the code information of the code file further includes: Judging whether at least one other code file is referenced in the code file; If so, scanning the code file and the at least one other code file, extracting the code information of the code file and the at least one other code file, and associating and recording the reference relationship between the code file and the at least one other code file in a tree structure.

3. The method according to claim 1, wherein, The organizing the variables in the code information, and storing the variables and the corresponding assignment information in a key-value pair manner further includes: Organizing the global variables in the code information, and storing the global variables and the corresponding assignment information in a key-value pair manner; And / or, Storing the variables and the corresponding assignment information in at least one function in the code information in a key-value pair manner and binding it to the function name; And / or, Parsing the traversal statements of at least one function in the code information, and storing the variables in the traversal statements and the corresponding assignment information in each traversal in a key-value pair manner and binding it to the function name.

4. The method according to claim 1, wherein, The storing at least one parameter in at least one function in the code information in the order of its call and binding it to the function name further includes: Extracting the assignment information of the parameters passed in when the function is called, and storing the parameters and the corresponding assignment information in a key-value pair manner and binding it to the function name.

5. The method according to claim 1, wherein, The assignment information contains reference relationships to other variables and / or parameters; The organizing the variables in the code information, and storing the variables and the corresponding assignment information in a key-value pair manner further includes: Parsing the assignment information, and replacing the referenced other variables and / or parameters with the corresponding assignment information of the other variables and / or parameters according to the reference relationship; Organizing the variables in the code information, and storing the variables and the replaced assignment information in a key-value pair manner.

6. The method according to claim 1, wherein, Detecting the code information in the cache to determine whether there is a code problem further includes: Detecting the variables and / or parameters in the cache and their corresponding assignment information to determine whether there is a code problem with the variables and / or parameters; wherein, the detection includes one or more of the following: whether the variables and / or parameters are declared before being referenced; whether the variables and / or parameters are assigned before being referenced; whether the assignment information of the variables and / or parameters conforms to the declaration information of the variables and / or parameters; and / or, Performing a function verification test based on the function information in the cache to determine whether the code information implements the function corresponding to the function information; wherein, the function information includes: parallel execution, error feedback, alarm, and / or file existence verification.

7. The method according to claim 1, wherein, The method further includes: When scanning a code file, performing a code logic test on the code file to determine whether there is a code problem in the code file; wherein, the code logic test includes one or more of the following: determining whether the existence of input information is monitored before a task is started, determining whether a retry mechanism is set for the task, determining whether a notification mechanism is set for task failure, determining the real-time nature of the input file, determining whether there is an insecure copy and / or a cross-machine copy, determining whether the account used for the copy is a public account, determining whether the recipients in the email notification are updated in a timely manner.

8. The method according to any one of claims 1-7, wherein, Marking and locating the code problem further includes: Determining corresponding code problem location information according to the code problem; Storing the code problem and the corresponding code problem location information in a code problem database.

9. The method according to claim 8, wherein, The method further includes: Obtaining the code problem from the code problem database and displaying it on a code problem display page.

10. A code scanning device, which includes: A scanning module adapted to scan a code file and extract the code information of the code file, wherein the code information includes variables, parameters, and / or functions; A caching module adapted to analyze and organize the code information and classify and cache the code information; A detection module adapted to detect the code information in the cache to determine whether there is a code problem in the code information; A marking and positioning module adapted to mark and locate the code problem if the detection module determines that there is a code problem in the code information; wherein, the caching module further includes: A variable unit adapted to organize the variables in the code information and store the variables and the corresponding assignment information in a key-value pair manner; and / or, A function unit adapted to locate the starting line number information and / or function information of at least one function in the code information and bind it to the corresponding function name; and / or, A parameter unit adapted to store at least one parameter in at least one function in the code information in the order of its call and bind it to the function name.

11. The device according to claim 10, wherein, The scanning module is further adapted to: Determine whether at least one other code file is referenced in the code file; If so, scan the code file and the at least one other code file, extract the code information of the code file and the at least one other code file, and record the reference relationship between the code file and the at least one other code file in a tree structure.

12. The apparatus according to claim 10, wherein, the variable unit is further adapted to: sort out the global variables in the code information and store the global variables and the corresponding assignment information in a key-value pair manner; and / or, store the variables in at least one function in the code information and the corresponding assignment information in a key-value pair manner bound to the function name; and / or, parse the traversal statements of at least one function in the code information, and store the variables in the traversal statements and the corresponding assignment information in a key-value pair manner bound to the function name for each traversal.

13. The apparatus according to claim 10, wherein, the parameter unit is further adapted to: extract the assignment information of the parameters passed in when the function is called, and store the parameters and the corresponding assignment information in a key-value pair manner bound to the function name.

14. The apparatus according to claim 10, wherein, the assignment information includes a reference relationship to other variables and / or parameters; the variable unit is further adapted to: parse the assignment information, and replace the other variables and / or parameters referred to according to the reference relationship with the corresponding assignment information of the other variables and / or parameters; sort out the variables in the code information and store the variables and the replaced assignment information in a key-value pair manner.

15. The apparatus according to claim 10, wherein, the detection module further includes: a variable parameter detection unit, adapted to detect the cached variables and / or parameters and their corresponding assignment information to determine whether there are code problems with the variables and / or parameters; wherein, the detection includes one or more of the following: whether the variables and / or parameters are declared before being referenced; whether the variables and / or parameters are assigned before being referenced; whether the assignment information of the variables and / or parameters conforms to the declaration information of the variables and / or parameters; and / or, a function detection unit, adapted to perform a function verification detection according to the cached function information to determine whether the code information implements the function corresponding to the function information; wherein, the function information includes: parallel execution, error feedback, alarm, and / or file existence verification.

16. The apparatus according to claim 10, wherein, the apparatus further includes: A code logic detection module, adapted to perform code logic detection on the code file when scanning the code file to determine whether there are code problems in the code file; wherein, the code logic detection includes one or more of the following: determining whether the existence of input information is monitored before the task starts, determining whether a retry mechanism is set for the task, determining whether a notification mechanism is set for task failure, determining the timeliness of the input file, determining whether there are non-secure copies and / or cross-machine copies, determining whether the account used for copying is a public account, and determining whether the recipients in the email notification are updated in a timely manner.

17. The apparatus according to any one of claims 10-16, wherein, the marker positioning module is further adapted to: determine corresponding code problem positioning information according to the code problem; store the code problem and the corresponding code problem positioning information in a code problem database.

18. The apparatus according to claim 17, wherein, the apparatus further includes: a display module, adapted to obtain the code problem from the code problem database and display it on a code problem display page.

19. A computing device, including: a processor, a memory, a communication interface, and a communication bus, and the processor, the memory, and the communication interface complete mutual communication through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction causes the processor to perform operations corresponding to the code scanning method according to any one of claims 1-9.

20. A computer storage medium, in which at least one executable instruction is stored, and the executable instruction causes a processor to perform operations corresponding to the code scanning method according to any one of claims 1-9.

Citation Information

Patent Citations

  • Makefile-based code static analysis method and device

    CN107832059A