Methods, devices, and storage media for determining risk codes

CN116521559BActive Publication Date: 2026-09-01TENCENT MUSIC ENTERTAINMENT TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310518438.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-09
Publication Date
2026-09-01
Estimated Expiration
2043-05-09

AI Technical Summary

Technical Problem

因此,人工测试无法保证可以触发Kotlin定义的函数中参数传参为空的问题,导致相关代码存在安全隐患

Benefits of technology

[0045] Since the second programming language does not allow null parameters by default, when null parameters are passed in the second programming language code, the target code will fail to run. Therefore, the parameter types that have caused null parameter passing issues in previous versions of the code can be identified as the target type, and this target type can be used as a reference condition for identifying risky code. Before running the target code, the target function defined in the second programming language can be identified first, and then the parameters in the target function whose parameter types are of the target type can be identified. This allows for the localization of null parameter passing issues in the target code, and thus timely detection of security vulnerabilities in the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116521559B_ABST
    Figure CN116521559B_ABST
Patent Text Reader

Abstract

This disclosure provides a method, apparatus, and storage medium for identifying risky code, belonging to the field of computer technology. Since the second programming language does not allow null parameters by default, when null parameters occur in the code of the second programming language, the target code will fail to run. Therefore, the types of parameters that have caused null parameter issues in historical versions of the code can be identified as target types, and these target types can be used as reference conditions for identifying risky code. Before running the target code, the target function defined by the second programming language can be identified in the target code, and further, the parameters in the target function whose parameter types are of the target type can be identified. This allows for the location of null parameter issues in the target code, enabling timely detection of security vulnerabilities in the code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a method, apparatus, and storage medium for determining risk codes. Background Technology

[0002] When developing Android applications, developers typically use Java and Kotlin to write the code. Kotlin stipulates that function parameters cannot be empty (i.e., no values ​​are assigned to them) when defining functions. In Java, default function parameters can be empty. Java code may call Kotlin-defined functions. When the Java code reaches a point where a Kotlin-defined function is called, if the function's parameters are empty, a runtime error will occur, causing the application to crash.

[0003] Generally, after an application is developed, technical personnel will conduct manual testing to identify problems and then modify the relevant code based on the test results.

[0004] During manual testing, an operator's actions might trigger an application call to a Kotlin-defined function with empty parameters, causing the application to crash. Alternatively, the operator's actions might not trigger a call to a Kotlin-defined function, or even if a function call is triggered, all parameters might be passed, preventing a crash. Therefore, manual testing cannot guarantee that empty parameter passing will occur in Kotlin-defined functions, potentially leading to security vulnerabilities in the related code. Summary of the Invention

[0005] This disclosure provides a method, apparatus, device, and storage medium for determining risk codes, which can solve the problems in related technologies. The technical solution is as follows:

[0006] Firstly, a method for determining risk codes is provided, the method comprising:

[0007] In the target code containing code in the first programming language and code in the second programming language, determine the target function defined by the second programming language, wherein the first programming language is a programming language that allows functions to pass empty parameters by default, and the second programming language is a programming language that does not allow functions to pass empty parameters by default.

[0008] Determine the target type parameter in the target function, where the target type is the type to which the target parameter belongs. The target parameter caused the historical version of the code to fail to run because the historical version of the code was empty during the execution of the historical version of the code corresponding to the target code.

[0009] Output the parameters of the target type in the target function.

[0010] In one possible implementation, the first programming language is Java and the second programming language is Kotlin.

[0011] In one possible implementation, determining the target function defined by the second programming language in the target code containing code from the first programming language and code from the second programming language includes:

[0012] In the AST (Abstract Syntax Tree) corresponding to the code of the first programming language in the target code, the target nodes of the function definition type are traversed. For each target node, it is determined whether the function corresponding to the target node is a function defined by the second programming language. If the function corresponding to the target node is a function defined by the second programming language, then the function corresponding to the target node is determined as the target function.

[0013] In one possible implementation, before determining whether the function corresponding to the target node is a function defined in Kotlin code, the method further includes:

[0014] It is determined that the target node contains parameters.

[0015] In one possible implementation, before outputting the parameter of the target type in the target function, the method further includes:

[0016] It is determined that the parameter is not marked as allowing null parameters in the definition statement of the objective function.

[0017] In one possible implementation, before determining the target function defined by the second programming language in the target code containing code of the first programming language and code of the second programming language, the method further includes:

[0018] The target lint rule and the target code are input into the compiler, wherein the target lint rule is used to instruct the compiler to determine the target function defined by the second programming language in the target code containing code of the first programming language and code of the second programming language, determine the parameters of the target type in the target function, and output the parameters of the target type in the target function.

[0019] In one possible implementation, the parameter of the target type in the target function is output, including:

[0020] The location of the parameter in the target code and modification instructions are displayed, wherein the modification instructions are used to prompt the user to mark the parameter as allowing null parameters in the definition statement of the target function.

[0021] In one possible implementation, the parameter of the target type in the target function is output, including:

[0022] An error slip is generated, wherein the error slip includes the position of the parameter in the target code and modification instruction information, the modification instruction information being used to instruct the user to mark the parameter as allowing null parameters in the definition statement of the target function.

[0023] Secondly, an apparatus for determining a risk code is provided, the apparatus comprising:

[0024] The determination module is used for:

[0025] In the target code containing code in the first programming language and code in the second programming language, determine the target function defined by the second programming language, wherein the first programming language is a programming language that allows functions to pass empty parameters by default, and the second programming language is a programming language that does not allow functions to pass empty parameters by default.

[0026] Determine the target type parameter in the target function, where the target type is the type to which the target parameter belongs. The target parameter caused the historical version of the code to fail to run because the historical version of the code was empty during the execution of the historical version of the code corresponding to the target code.

[0027] The output module is used to output the parameters of the target type in the target function.

[0028] In one possible implementation, the first programming language is Java and the second programming language is Kotlin.

[0029] In one possible implementation, the determining module is configured to:

[0030] In the AST (Abstract Syntax Tree) corresponding to the code of the first programming language in the target code, the target nodes of the function definition type are traversed. For each target node, it is determined whether the function corresponding to the target node is a function defined by the second programming language. If the function corresponding to the target node is a function defined by the second programming language, then the function corresponding to the target node is determined as the target function.

[0031] In one possible implementation, the determining module is further configured to:

[0032] It is determined that the target node contains parameters.

[0033] In one possible implementation, the determining module is further configured to:

[0034] It is determined that the parameter is not marked as allowing null parameters in the definition statement of the objective function.

[0035] In one possible implementation, the device further includes:

[0036] An input module is used to input the target lint rule and the target code into the compiler, wherein the target lint rule is used to instruct the compiler to determine the target function defined by the second programming language in the target code containing code of the first programming language and code of the second programming language, determine the parameters of the target type in the target function, and output the parameters of the target type in the target function.

[0037] In one possible implementation, the output module is used for:

[0038] The location of the parameter in the target code and modification instructions are displayed, wherein the modification instructions are used to prompt the user to mark the parameter as allowing null parameters in the definition statement of the target function.

[0039] In one possible implementation, the output module is used for:

[0040] An error slip is generated, wherein the error slip includes the position of the parameter in the target code and modification instruction information, the modification instruction information being used to instruct the user to mark the parameter as allowing null parameters in the definition statement of the target function.

[0041] Thirdly, a computer device is provided, comprising a memory and a processor, the memory for storing computer instructions; the processor executes the computer instructions stored in the memory to cause the computer device to perform the method of the first aspect and its possible implementations.

[0042] Fourthly, a computer-readable storage medium is provided that stores computer program code, and in response to the computer program code being executed by a computer device, the computer device executes the method of the first aspect and its possible implementations.

[0043] Fifthly, a computer program product is provided, the computer program product including computer program code, and a method for the computer device to execute the first aspect and its possible implementations in response to the computer program code being executed by a computer device.

[0044] The technical solutions provided by the embodiments of this disclosure may include the following beneficial effects:

[0045] Since the second programming language does not allow null parameters by default, when null parameters are passed in the second programming language code, the target code will fail to run. Therefore, the parameter types that have caused null parameter passing issues in previous versions of the code can be identified as the target type, and this target type can be used as a reference condition for identifying risky code. Before running the target code, the target function defined in the second programming language can be identified first, and then the parameters in the target function whose parameter types are of the target type can be identified. This allows for the localization of null parameter passing issues in the target code, and thus timely detection of security vulnerabilities in the code. Attached Figure Description

[0046] To more clearly illustrate the technical solutions in the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0047] Figure 1 This is a schematic diagram of the structure of a terminal provided in an embodiment of this disclosure;

[0048] Figure 2 This is a schematic diagram of the structure of a server provided in an embodiment of this disclosure;

[0049] Figure 3 This is a flowchart illustrating a method for determining risk codes provided in an embodiment of this disclosure;

[0050] Figure 4 This is a schematic diagram of a file list of object code provided in an embodiment of this disclosure;

[0051] Figure 5 This is a schematic diagram of an AST corresponding to a Java file provided in an embodiment of this disclosure;

[0052] Figure 6 This is a schematic diagram of the code for a Kotlin programming language provided in an embodiment of this disclosure;

[0053] Figure 7 This is a schematic diagram of the code for a Java programming language provided in an embodiment of this disclosure;

[0054] Figure 8 This is a schematic diagram illustrating a specific workflow for determining risk codes provided in an embodiment of this disclosure;

[0055] Figure 9 This is a schematic diagram of the structure of an apparatus for determining risk codes provided in an embodiment of this disclosure;

[0056] Figure 10 This is a schematic diagram of the structure of a terminal provided in an embodiment of this disclosure. Detailed Implementation

[0057] This disclosure provides a method for identifying risk codes. This method is used to identify risk codes in relevant codes that may have issues with empty parameter passing, so as to prompt technicians to review and modify the risk codes.

[0058] This method can be implemented using computer devices, which can be terminals or servers. Terminals can be mobile phones, tablets, laptops, desktop computers, etc. Servers can be a single server or a group of multiple devices.

[0059] From a hardware perspective, the terminal's structure can be as follows: Figure 1 As shown, it includes a processor 110, a memory 120, and a display unit 130.

[0060] Processor 110 can be a CPU (central processing unit) or SoC (system on chip), etc., and processor 210 can be used to execute various instructions involved in the method.

[0061] The memory 120 may include various volatile or non-volatile memories, such as SSD (solid state disk) and DRAM (dynamic random access memory). The memory 120 can be used for pre-stored data, intermediate data, and result data in the process of determining risk codes, such as target codes and Lint rules.

[0062] The display component 130 can be a standalone screen, or a screen integrated with the terminal body, a projector, etc. The screen can be a touch screen or a non-touch screen. The display component is used to display code, such as target code.

[0063] In addition to processors and memory, terminals may also include communication components, audio acquisition components, audio output components, etc.

[0064] Communication components can be wired network connectors, WiFi (wireless fidelity) modules, Bluetooth modules, cellular communication modules, etc. These components can be used to transmit data with other devices, such as servers or other terminals.

[0065] The audio acquisition component can be a microphone, used to capture the user's voice. The audio output component can be a speaker, headphones, etc., used to play audio.

[0066] From a hardware perspective, the server's structure can be as follows: Figure 2 As shown, it includes a processor 210 and a memory 220.

[0067] The processor 210 can be a CPU or SoC, etc., and the processor 210 can be used to execute various instructions involved in the method.

[0068] The memory 220 may include various volatile or non-volatile memories, such as SSDs, DRAM, etc. The memory 220 can be used to store pre-data, intermediate data, and result data in the process of determining risk codes, such as target codes, Lint rules, etc.

[0069] In addition to processors and memory, servers may also include communication components.

[0070] Communication components can be wired network connectors, WiFi modules, Bluetooth modules, cellular communication modules, etc. These components can be used to transmit data with other devices, such as servers or other terminals.

[0071] This disclosure uses a terminal as an example to describe the solution in detail. Other situations are similar and will not be described in detail here.

[0072] The following is a description of several terms used in this embodiment:

[0073] Java: The name of a programming language, short for JavaScript. This language allows functions to pass empty parameters by default. In Java, functions can also be called methods.

[0074] Kotlin: The name of a programming language that, by default, does not allow empty function arguments.

[0075] Lint is a tool for scanning code for defects. In practical applications, technicians can write corresponding Lint rules to identify risky code with potential problems.

[0076] An Abstract Syntax Tree (AST) is a tree-like representation of the syntactic structure of source code. In practice, a piece of code can be input into an AST parser to obtain its AST. For example, the AST of a piece of code can be specifically represented as follows:

[0077]

[0078] In this AST, Node1, Node2, Node3, Node4, and Node5 are the nodes of the AST. Type indicates the type of the node. The positions of the first, second, third, fourth, and fifth ellipses indicate the relevant attributes of the corresponding node (e.g., the name of the node). The last ellipse indicates that there are other nodes.

[0079] During Android application development, multiple engineers can simultaneously write code for different modules using Java and Kotlin programming languages. Furthermore, engineers can design different schemes for identifying risky code and write corresponding lint rules. After the relevant code is written, lint rules can be used to identify risky code. For example, identifying code with issues such as passing null parameters.

[0080] This disclosure provides a method for determining risk codes for the aforementioned application scenarios. The processing flow of this method can be as follows: Figure 3 As shown, the processing steps include the following:

[0081] 301. In the target code containing code in the first programming language and code in the second programming language, determine the target function defined by the second programming language.

[0082] The first programming language is Java, which allows empty function parameters by default. The second programming language is Kotlin, which does not allow empty function parameters by default. The target code consists of multiple Java files and multiple Kotlin files. The list of target code files can be as follows: Figure 4 As shown. The target function is a function called in the code of the first programming language, and this function is defined in the second programming language.

[0083] There are several ways to determine the objective function:

[0084] Method 1: In the Abstract Syntax Tree (AST) corresponding to the code in the first programming language of the target code, traverse the target nodes of function definition types. For each target node, determine whether the function corresponding to that node is a function defined in the second programming language. If the function corresponding to the target node is a function defined in the second programming language, then identify the function corresponding to the target node as the target function. If the function corresponding to the target node is not a function defined in the second programming language, then traverse to the next target node.

[0085] The AST includes multiple nodes, each containing relevant information such as the node's name, type, and parameters.

[0086] In implementation, the terminal can traverse each file in the target code. Upon reaching each file, it first determines whether the file contains code in the Java programming language.

[0087] If the file is Java programming language code (such as...) Figure 4 For files like code1.java, code3.java, code4.java, and code6.java, we can obtain the AST corresponding to that file and traverse its nodes. Each time we encounter a node of type function definition (e.g., UCallExpression), we identify that node as the target node and determine the file containing the function corresponding to that target node. Further, we determine whether that file contains code in the Kotlin programming language (e.g.,...). Figure 4 If the files (code2.kt, code5.kt, code7.kt, code9.kt, etc.) are present, then each function in that file is traversed. For each function encountered, it is determined whether that function corresponds to the target node, until the function corresponding to the target node is found in the file, i.e., the target function is determined. If not, the next target node in the AST is traversed.

[0088] like Figure 5 As shown, the AST corresponding to code1.java in the target code is as follows: Figure 5 As shown, when traversing to Node1, since Node1 is of type UCallExpression, it can be identified as the target node. The function corresponding to Node1 is Function1, and the code defining Function1 is in the file code12.kt. The code in code12.kt is as follows: Figure 6As shown. The file code12.kt contains Kotlin programming language code; therefore, Function1 can be identified as the target function. When traversing to Node4, since Node4 is of type UCallExpression, Node4 can be identified as the target node. The function corresponding to Node4 is Function6, and the code defining Function6 is in the file code10.java. The code in code10.java is as follows: Figure 7 As shown. The file code10.java is Java programming language code, therefore, we can continue to traverse the next node in the AST corresponding to code1.java.

[0089] If the file is not Java programming language code, then iterate through the next file in the target code.

[0090] Optionally, before determining the file containing the function corresponding to the target node, it's possible to first determine if the target node contains parameters. If parameters exist, then the file containing the function corresponding to the target node is determined. If no parameters exist, the process can continue traversing the next node in the AST. Since this approach targets functions defined in the Kotlin programming language that contain parameters, target nodes without parameters can be left unprocessed. This saves processing resources and speeds up the identification of risky code.

[0091] The specific processing procedure of Method 1 above can be as follows: Figure 8 As shown.

[0092] Method 2: In the second programming language code within the target code, each time a function is encountered, it is determined whether the function has parameters. If the function does not have parameters, the next function is encountered in the second programming language code within the target code. If the function has parameters, it is determined whether the first programming language code within the target code calls the function. If so, the function can be identified as the target function. If not, the next function is encountered in the second programming language code within the target code, and the above process is repeated.

[0093] In implementation, the terminal can traverse each file in the target code. When traversing to a file, it first determines whether the file is code in the Kotlin programming language.

[0094] If the file contains Kotlin programming language code, you can iterate through the functions within that file, checking for parameters at each function. If the function has no parameters, iterate through the next file in the target code. If the function has parameters, iterate through the files in the target code. For each Java file encountered, the target function can be determined using the following two methods:

[0095] First, determine if the function is called in the Java file. If so, that function can be identified as the target function. If not, iterate through the next Java file until the file that calls the function is found, or until all Java files have been traversed.

[0096] Second, traverse the nodes of the AST corresponding to the Java file. For each node, determine whether the function corresponding to that node is a function defined in the Kotlin programming language. If it is, then the function corresponding to that node is identified as the target function. If not, then traverse the next Java file until the Java file that calls the function is found, or until all Java files have been traversed.

[0097] The processing described in Method 1 and Method 2 can be performed by the compiler. Therefore, the target Lint rule and target code can be input into the compiler before performing the above processing.

[0098] The target lint rules can include information such as error identifier (ISSUE_ID) and error name (ISSUE_Title), which are used to instruct the compiler to determine the target function defined by the second programming language in the target code containing code of the first programming language and code of the second programming language, determine the parameters of the target type in the target function, and output the parameters of the target type in the target function.

[0099] In implementation, the target lint rule can first be compiled into a corresponding compressed package. The compressed package, XML file, and target code of the target lint rule are then input into the compiler. The compiler can then compile the target code, identifying risky code during the compilation process based on the target lint rule.

[0100] 302, Determine the parameters of the target type in the objective function.

[0101] Among them, the target type is the type to which the target parameter belongs. During the execution of the historical version of the target code, the historical version of the code failed because the parameter was passed empty.

[0102] During implementation, when problems occur while running historical code versions, error reports are generated. These error reports include the location, cause, type, and version of the error in the historical code. Technical personnel can identify error reports with the error type of empty parameter passing from these reports, determine the parameters in the error reports as target parameters, and summarize the types of the target parameters to obtain a target type set.

[0103] The objective function can include multiple parameters. Upon encountering each parameter, its type can be determined, and it can be checked whether that type belongs to the target type set. If the parameter's type belongs to the target type set, it can be identified as a parameter of the target type. If the parameter's type does not belong to the target type set, the type of the next parameter in the objective function can be determined.

[0104] The specific processing procedure for this step can be as follows: Figure 8 As shown.

[0105] 303 indicates that the parameter was not marked as allowing null parameters in the definition statement of the objective function.

[0106] During implementation, after identifying the parameter of the target type, it's determined whether that parameter is marked as allowing null arguments in the target function's definition. If so, it means that the target code will not encounter errors when the parameter is passed null. Therefore, no processing is needed for this parameter, and the process moves on to identifying the next parameter of the target function. This eliminates the need for technical personnel to check the output target type parameters and then determine if they need modification, thus speeding up the identification of risky code. If not, the file containing the target function and the parameter's location within that file can be determined; the parameter's location can be indicated by its line number.

[0107] In one possible implementation, this step can be omitted; simply iterate through the target function and output the parameter of the target type.

[0108] 304, outputs the parameters of the target type in the target function.

[0109] Method 1 displays the location of the parameters in the target code and modification instructions.

[0110] The modification instruction information is used to prompt the user to mark the parameters in the definition statement of the target function as allowing empty parameters.

[0111] In implementation, the terminal can display information such as the parameter name, the file name where the target function is located, the definition statement of the target function, the parameter's location in the file, the error identifier (ISSUE_ID), and the error name (ISSUE_Title) to prompt technical personnel to review and modify the relevant code. In one possible implementation, the terminal can highlight the parameters in the target function's definition statement, for example, by displaying them in red. In another possible implementation, after determining the target type parameter in the target function, the terminal can automatically add a flag indicating that null parameters are allowed at the location where the parameter is defined.

[0112] Method 2: Generate an incorrect bill of lading.

[0113] The error message can include the location of the parameter in the target code and modification instructions. The location of the parameter in the target code can include the name of the file containing the parameter and its position within that file. The modification instructions can include information related to the problem of an empty parameter, such as the error identifier and error name. The error message may also include the definition statement of the target function and the name of the parameter.

[0114] In implementation, the terminal can generate an error report and send it to the terminal of the technician who wrote the code, prompting the technician to review and modify the code. In one possible implementation, after determining the parameter of the target type in the objective function, the terminal can automatically add a flag indicating that null parameters are allowed at the location where the parameter is defined.

[0115] The terminal can continue iterating through the next parameter of the target function until all parameters of the target function have been traversed, then iterate through the next function, and so on, until all parameters in all target functions in the target code have been traversed, identifying all potentially vulnerable code within the target code that might have null parameter passing. Thus, when technicians or the terminal modify the vulnerable code, the modified code will not exhibit null parameter passing issues when the target code is run. Therefore, this method can identify security vulnerabilities in the target code, and modifications by technicians or the terminal can reduce the probability of problems occurring during runtime.

[0116] After technicians modify the risk code, or add code to the target code, steps 301 to 304 above can be performed only on the modified or newly added code. This improves processing efficiency.

[0117] The method provided in this disclosure allows for the identification of null parameters in the target code. Since the second programming language does not allow null parameters by default, null parameters will cause the target code to fail. Therefore, the parameter types that have caused null parameter issues in previous versions of the code can be identified as target types, which can then be used as a reference for identifying risky code. Before running the target code, the target function defined in the second programming language can be identified, and further, the parameters in the target function whose parameter types are of the target type can be determined. This allows for the location of null parameter issues in the target code, enabling timely detection of security vulnerabilities.

[0118] Based on the same technical concept, embodiments of this disclosure also provide an apparatus for determining risk codes, such as... Figure 9 As shown, the device includes:

[0119] Determine module 910, used for:

[0120] In the target code containing code in the first programming language and code in the second programming language, determine the target function defined by the second programming language, wherein the first programming language is a programming language that allows functions to pass empty parameters by default, and the second programming language is a programming language that does not allow functions to pass empty parameters by default.

[0121] Determine the target type of the parameters in the target function. The target type is the type of the target parameter. The historical version of the code failed to run because the target parameter was passed as an empty parameter.

[0122] Output module 920 is used to output the parameters of the target type in the target function.

[0123] In one possible implementation, the first programming language is Java and the second programming language is Kotlin.

[0124] In one possible implementation, module 910 is defined for:

[0125] In the AST (Abstract Syntax Tree) corresponding to the code of the first programming language in the target code, the target nodes of the function definition type are traversed. For each target node, it is determined whether the function corresponding to the target node is a function defined in the second programming language. If the function corresponding to the target node is a function defined in the second programming language, then the function corresponding to the target node is determined as the target function.

[0126] In one possible implementation, the determining module 910 is also used for:

[0127] Determine if parameters exist in the target node.

[0128] In one possible implementation, the determining module 910 is also used for:

[0129] It is determined that the parameters are not marked as allowing empty parameters in the definition statement of the objective function.

[0130] In one possible implementation, the device further includes:

[0131] Input module 930 is used to input target Lint rules and target code into the compiler. The target Lint rules are used to instruct the compiler to determine the target function defined by the second programming language in the target code containing code of the first programming language and code of the second programming language, determine the parameters of the target type in the target function, and output the parameters of the target type in the target function.

[0132] In one possible implementation, the output module 920 is used for:

[0133] Displays the location of the parameters in the target code and modification instructions. The modification instructions are used to prompt the user to mark the parameters in the definition statement of the target function as allowing null parameters.

[0134] In one possible implementation, the output module 920 is used for:

[0135] Generate an error message, which includes the location of the parameter in the target code and modification instructions. The modification instructions are used to instruct the user to mark the parameter as allowing null parameters in the definition statement of the target function.

[0136] The apparatus provided in this disclosure allows for the identification of null parameters in the target code. Since the second programming language does not allow null parameters by default, null parameters will cause the target code to fail. Therefore, the parameter types that have caused null parameter issues in previous versions of the code can be identified as target types, which can then be used as a reference for identifying risky code. Before running the target code, the target function defined by the second programming language can be identified within the target code, and further, the parameters in the target function whose parameter types are of the target type can be determined. This allows for the location of null parameter issues in the target code, enabling timely detection of security vulnerabilities.

[0137] It should be noted that the risk code determination apparatus provided in the above embodiments is only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the risk code determination apparatus and the risk code determination method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process is detailed in the method embodiments, which will not be repeated here.

[0138] Figure 10 A structural block diagram of a terminal 1000 provided in an embodiment of this disclosure is shown. This terminal can be any of the terminals described in the above embodiments. The terminal 1000 can be a portable mobile terminal, such as a smartphone, tablet computer, MP3 player (Moving Picture Experts Group Audio Layer III), MP4 player (Moving Picture Experts Group Audio Layer IV), laptop computer, or desktop computer. The terminal 1000 may also be referred to as a user device, portable terminal, laptop terminal, desktop terminal, or other names.

[0139] Typically, terminal 1000 includes a processor 1001 and a memory 1002.

[0140] Processor 1001 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 1001 may be implemented using at least one hardware form selected from DSP (digital signal processing), FPGA (field-programmable gate array), and PLA (programmable logic array). Processor 1001 may also include a main processor and a coprocessor. The main processor, also known as the CPU, is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 1001 may integrate a GPU (graphics processing unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, processor 1001 may also include an AI (artificial intelligence) processor, which is used to handle computational operations related to machine learning.

[0141] The memory 1002 may include one or more computer-readable storage media, which may be non-transitory. The memory 1002 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1002 are used to store at least one instruction, which is executed by the processor 1001 to implement the methods provided in the embodiments of this disclosure.

[0142] In some embodiments, the terminal 1000 may also optionally include a peripheral device interface 1003 and at least one peripheral device. The processor 1001, memory 1002, and peripheral device interface 1003 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral device interface 1003 via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of the following: a radio frequency circuit 1004, a display screen 1005, a camera assembly 1006, an audio circuit 1007, a positioning assembly 1008, and a power supply 1009.

[0143] Peripheral device interface 1003 can be used to connect at least one I / O (input / output) related peripheral device to processor 1001 and memory 1002. In some embodiments, processor 1001, memory 1002 and peripheral device interface 1003 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 1001, memory 1002 and peripheral device interface 1003 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.

[0144] The radio frequency (RF) circuit 1004 is used to receive and transmit RF signals, also known as electromagnetic signals. The RF circuit 1004 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 1004 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals back into electrical signals. Optionally, the RF circuit 1004 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, etc. The RF circuit 1004 can communicate with other terminals through at least one wireless communication protocol. This wireless communication protocol includes, but is not limited to: the World Wide Web, metropolitan area networks, intranets, various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks, and / or WiFi (wireless fidelity) networks. In some embodiments, the RF circuit 1004 may also include circuitry related to NFC (near field communication), which is not limited in this application.

[0145] Display screen 1005 is used to display a user interface (UI). This UI may include graphics, text, icons, videos, and any combination thereof. When display screen 1005 is a touch display screen, it also has the ability to collect touch signals on or above its surface. These touch signals can be input as control signals to processor 1001 for processing. In this case, display screen 1005 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there may be one display screen 1005, disposed on the front panel of terminal 1000; in other embodiments, there may be at least two display screens, disposed on different surfaces of terminal 1000 or in a folded design; in still other embodiments, display screen 1005 may be a flexible display screen, disposed on a curved or folded surface of terminal 1000. Furthermore, display screen 1005 may be configured as a non-rectangular irregular shape, i.e., a non-rectangular screen. Display screen 1005 may be made of materials such as LCD (liquid crystal display) or OLED (organic light-emitting diode).

[0146] The camera assembly 1006 is used to acquire images or videos. Optionally, the camera assembly 1006 includes a front-facing camera and a rear-facing camera. Typically, the front-facing camera is located on the front panel of the terminal, and the rear-facing camera is located on the back of the terminal. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (virtual reality) shooting, or other fusion shooting functions. In some embodiments, the camera assembly 1006 may also include a flash. The flash can be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm-light flash and a cool-light flash, which can be used for light compensation at different color temperatures.

[0147] The audio circuit 1007 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, converting the sound waves into electrical signals that are input to the processor 1001 for processing, or input to the radio frequency circuit 1004 for voice communication. For stereo sound acquisition or noise reduction purposes, multiple microphones may be used, each positioned at a different location on the terminal 1000. The microphone may also be an array microphone or an omnidirectional microphone. The speaker is used to convert electrical signals from the processor 1001 or the radio frequency circuit 1004 into sound waves. The speaker may be a conventional diaphragm speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can convert electrical signals not only into audible sound waves but also into inaudible sound waves for purposes such as distance measurement. In some embodiments, the audio circuit 1007 may also include a headphone jack.

[0148] The positioning component 1008 is used to determine the current geographical location of the positioning terminal 1000 in order to enable navigation or LBS (location-based service). The positioning component 1008 can be a positioning component based on GPS (global positioning system) or BeiDou system.

[0149] Power supply 1009 is used to power the various components in terminal 1000. Power supply 1009 can be AC ​​power, DC power, a disposable battery, or a rechargeable battery. When power supply 1009 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery that is charged via a wired line, and a wireless rechargeable battery is a battery that is charged via a wireless coil. The rechargeable battery can also be used to support fast charging technology.

[0150] In some embodiments, the terminal 1000 further includes one or more sensors 1010. The one or more sensors 1010 include, but are not limited to: an accelerometer 1011, a gyroscope 1012, a pressure sensor 1013, a fingerprint sensor 1014, an optical sensor 1015, and a proximity sensor 1016.

[0151] Accelerometer 1011 can detect the magnitude of acceleration along the three coordinate axes of a coordinate system established by terminal 1000. For example, accelerometer 1011 can be used to detect the components of gravitational acceleration along the three coordinate axes. Processor 1001 can control display screen 1005 to display the user interface in either a landscape or portrait view based on the gravitational acceleration signal acquired by accelerometer 1011. Accelerometer 1011 can also be used for games or for acquiring user motion data.

[0152] The gyroscope sensor 1012 can detect the orientation and rotation angle of the terminal 1000. The gyroscope sensor 1012, in conjunction with the accelerometer sensor 1011, can collect 3D motion data from the user on the terminal 1000. Based on the data collected by the gyroscope sensor 1012, the processor 1001 can perform the following functions: motion sensing (e.g., changing the UI based on the user's tilt), image stabilization during shooting, game control, and inertial navigation.

[0153] The pressure sensor 1013 can be disposed on the side bezel of the terminal 1000 and / or on the lower layer of the display screen 1005. When the pressure sensor 1013 is disposed on the side bezel of the terminal 1000, it can detect the user's grip signal on the terminal 1000, and the processor 1001 can perform left / right hand recognition or quick operation based on the grip signal collected by the pressure sensor 1013. When the pressure sensor 1013 is disposed on the lower layer of the display screen 1005, the processor 1001 can control the operable controls on the UI interface based on the user's pressure operation on the display screen 1005. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.

[0154] The fingerprint sensor 1014 is used to collect a user's fingerprint. The processor 1001 identifies the user based on the fingerprint collected by the fingerprint sensor 1014, or vice versa. When the user's identity is identified as trusted, the processor 1001 authorizes the user to perform relevant sensitive operations, including unlocking the screen, viewing encrypted information, downloading software, making payments, and changing settings. The fingerprint sensor 1014 can be located on the front, back, or side of the terminal 1000. When the terminal 1000 has physical buttons or a manufacturer's logo, the fingerprint sensor 1014 can be integrated with the physical buttons or manufacturer's logo.

[0155] An optical sensor 1015 is used to collect ambient light intensity. In one embodiment, the processor 1001 can control the display brightness of the display screen 1005 based on the ambient light intensity collected by the optical sensor 1015. Specifically, when the ambient light intensity is high, the display brightness of the display screen 1005 is increased; when the ambient light intensity is low, the display brightness of the display screen 1005 is decreased. In another embodiment, the processor 1001 can also dynamically adjust the shooting parameters of the camera assembly 1006 based on the ambient light intensity collected by the optical sensor 1015.

[0156] The proximity sensor 1016, also known as a distance sensor, is typically mounted on the front panel of the terminal 1000. The proximity sensor 1016 is used to detect the distance between the user and the front of the terminal 1000. In one embodiment, when the proximity sensor 1016 detects that the distance between the user and the front of the terminal 1000 is gradually decreasing, the processor 1001 controls the display screen 1005 to switch from a screen-on state to a screen-off state; when the proximity sensor 1016 detects that the distance between the user and the front of the terminal 1000 is gradually increasing, the processor 1001 controls the display screen 1005 to switch from a screen-off state to a screen-on state.

[0157] Those skilled in the art will understand that Figure 10 The structure shown does not constitute a limitation on terminal 1000 and may include more or fewer components than shown, or combine certain components, or use different component arrangements.

[0158] In this disclosure, a computer-readable storage medium is also provided, such as a memory including instructions that can be executed by a processor in a terminal to complete the method for performing interactive operations as described above. This computer-readable storage medium can be non-transitory. For example, the computer-readable storage medium can be ROM (read-only memory), RAM (random access memory), CD-ROM, magnetic tape, floppy disk, and optical data storage devices, etc.

[0159] It should be noted that the information (including but not limited to user equipment information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals (including but not limited to signals transmitted between user terminals and other devices) involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0160] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0161] The above description is only some possible embodiments of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for determining risk codes, characterized in that, The method includes: In the AST (Abstract Syntax Tree) corresponding to the code of the first programming language in the target code, the target nodes of the function definition type are traversed. For each target node, it is determined whether the function corresponding to the target node is a function defined in the second programming language. If the function corresponding to the target node is a function defined in the second programming language, then the function corresponding to the target node is determined as the target function. The target code includes the first programming language and the second programming language. The first programming language is a programming language that allows empty parameter passing for functions by default, and the second programming language is a programming language that does not allow empty parameter passing for functions by default. Determine the target type parameter in the target function, where the target type is the type to which the target parameter belongs. The target parameter caused the historical version of the code to fail to run because the historical version of the code was empty during the execution of the historical version of the code corresponding to the target code. Output the parameters of the target type in the target function.

2. The method according to claim 1, characterized in that, The first programming language is Java, and the second programming language is Kotlin.

3. The method according to claim 2, characterized in that, Before determining whether the function corresponding to the target node is a function defined in the Kotlin programming language, the method further includes: It is determined that parameters exist in the target node.

4. The method according to claim 1, characterized in that, Before outputting the parameters of the target type in the target function, the method further includes: It is determined that the parameter is not marked as allowing null parameters in the definition statement of the objective function.

5. The method according to claim 1, characterized in that, The method further includes: The target lint rule and the target code are input into the compiler, wherein the target lint rule is used to instruct the compiler to determine the target function defined by the second programming language in the target code containing code of the first programming language and code of the second programming language, determine the parameters of the target type in the target function, and output the parameters of the target type in the target function.

6. The method according to any one of claims 1-5, characterized in that, The parameters of the target type in the output objective function include: The location of the parameter in the target code and modification instructions are displayed, wherein the modification instructions are used to prompt the user to mark the parameter as allowing null parameters in the definition statement of the target function.

7. The method according to any one of claims 1-5, characterized in that, The parameters of the target type in the output objective function include: An error slip is generated, wherein the error slip includes the position of the parameter in the target code and modification instruction information, the modification instruction information being used to instruct the user to mark the parameter as allowing null parameters in the definition statement of the target function.

8. A computer device, characterized in that, The computer device includes a memory and a processor, the memory being used to store computer instructions; The processor executes computer instructions stored in the memory to cause the computer device to perform the method according to any one of claims 1-7.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program code, and in response to the computer program code being executed by a computer device, the computer device performs the method of any one of claims 1-7.

Citation Information

Patent Citations

  • JavaScript function parameter mismatch detection method based on static program analysis

    CN111694570A

  • Code debugging method and device, electronic equipment and readable storage medium

    CN114816973A