CN111338794A - Memory out-of-range monitoring method and device and storage medium - Google Patents

Memory out-of-range monitoring method and device and storage medium Download PDF

Info

Publication number
CN111338794A
CN111338794A CN202010099362.6A CN202010099362A CN111338794A CN 111338794 A CN111338794 A CN 111338794A CN 202010099362 A CN202010099362 A CN 202010099362A CN 111338794 A CN111338794 A CN 111338794A
Authority
CN
China
Prior art keywords
memory
access
information
address
size
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010099362.6A
Other languages
Chinese (zh)
Inventor
赵明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Dongchayun Information Technology Co ltd
Original Assignee
Suzhou Dongchayun Information Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Dongchayun Information Technology Co ltd filed Critical Suzhou Dongchayun Information Technology Co ltd
Priority to CN202010099362.6A priority Critical patent/CN111338794A/en
Publication of CN111338794A publication Critical patent/CN111338794A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3644Software debugging by instrumenting at runtime

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application discloses a memory out-of-range monitoring method, which comprises the following steps: determining running information of the source code; and confirming the out-of-range condition of the memory based on the data source memory in the operation information. The application also discloses a storage medium and a memory out-of-range monitoring device, and the memory out-of-range monitoring method, the storage medium and the device can effectively monitor the memory out-of-range condition.

Description

Memory out-of-range monitoring method and device and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for monitoring memory boundary crossing, and a storage medium.
Background
As an improper memory operation, the memory violation is not only likely to destroy other data in use in the program, but also likely to affect other running programs and even the whole system in a serious case, and how to effectively monitor the memory violation becomes an urgent problem to be solved.
Disclosure of Invention
The embodiment of the application provides a memory out-of-range monitoring method, a device and a storage medium, which can determine the memory out-of-range condition according to the running information of a source code.
The technical scheme of the embodiment of the application is realized as follows:
determining running information of the source code;
and confirming the out-of-range condition of the memory based on the data source memory in the operation information.
In the foregoing solution, the determining the running information of the source code includes:
determining memory application information of a source code;
the memory application information includes at least one of: the memory comprises a target memory, a memory block head address and a first address field.
In the foregoing solution, the determining the running information of the source code includes:
determining the memory use information of the source code based on the memory application information;
the memory usage information at least comprises: the data source memory, the first access address and the size of the residual memory.
In the foregoing solution, the determining that the memory boundary-crossing condition is based on the data source memory in the source code running information includes:
under the condition that a first access address exists in the memory application information, judging whether the size of the data source memory is larger than that of the target memory;
and confirming that the memory access of the first access address is out of bounds under the condition that the size of the data source memory is larger than that of the target memory.
In the foregoing solution, the determining that the memory boundary-crossing condition is based on the data source memory in the source code running information includes:
under the condition that a first access address does not exist in the memory application information, judging whether the first access address exists in a first address field in the memory application information or not;
under the condition that the first access address exists in the first address field, judging whether the size of the data source memory is larger than the size of the residual memory;
confirming that the memory access of the first access address is out of bounds under the condition that the size of the data source memory is larger than the size of the residual memory; or, confirming that the memory access of the first access address is out of bounds under the condition that the first access address does not exist in the first address field.
The present application further provides a memory cross-border monitoring device, the device includes:
the determining unit is used for determining the running information of the source code;
and the confirming unit is used for confirming the out-of-range condition of the memory based on the data source memory in the operation information.
In the foregoing solution, the determining device is further configured to:
determining memory application information of a source code;
the memory application information includes at least one of: the memory comprises a target memory, a memory block head address and a first address field.
In the foregoing solution, the determining device is further configured to:
determining the memory use information of the source code based on the memory application information;
the memory usage information at least comprises: the data source memory, the first access address and the size of the residual memory.
In the above scheme, the apparatus further comprises:
the judging unit is used for judging whether the size of the data source memory is larger than that of the target memory under the condition that the first access address exists in the memory application information;
the confirming device is further configured to confirm that the memory access of the first access address is out of bounds when the size of the data source memory is larger than the size of the destination memory.
In the foregoing solution, the determining unit is configured to determine whether a first access address exists in a first address field in the memory application information under the condition that the first access address does not exist in the memory application information; under the condition that the first access address exists in the first address field, judging whether the size of the data source memory is larger than the size of the residual memory;
the confirming unit is further configured to confirm that the memory access of the first access address is out of bounds when the size of the data source memory is larger than the size of the remaining memory; or, confirming that the memory access of the first access address is out of bounds under the condition that the first access address does not exist in the first address field.
According to the memory out-of-range monitoring method, device and storage medium provided by the embodiment of the application, the memory out-of-range condition is confirmed by determining the running information of the source code and based on the data source memory in the running information, the memory application information and the memory use information of the source code are further determined by determining the running information of the source code, and whether the memory access of the first access address is out of range or not is confirmed by judging the size relation between the data source memory and the target memory or the size relation between the data source memory and the rest memory on the basis of matching the memory block head address in the memory application information and the first access address in the memory use information. In view of the uniqueness of the access address and the memory block head address, the method for confirming whether the memory access is out of range based on address matching has high accuracy, can more effectively detect the condition of access out of range, improves the stability and reliability of source codes, and improves the software quality.
Drawings
Fig. 1 is a first schematic view illustrating an alternative flow chart of a memory out-of-range monitoring method according to an embodiment of the present disclosure;
FIG. 2 is a schematic diagram illustrating an alternative process for determining running information of source code according to an embodiment of the present application;
fig. 3 is a schematic view illustrating an alternative flow chart of a memory out-of-range monitoring method according to an embodiment of the present application;
fig. 4 is a schematic diagram of a memory out-of-range monitoring method according to an embodiment of the present disclosure;
fig. 5 is a schematic diagram illustrating an alternative structure of a memory out-of-range monitoring apparatus according to an embodiment of the present disclosure;
fig. 6 is a schematic diagram of a hardware configuration of the memory out-of-range monitoring apparatus according to the embodiment of the present invention.
Detailed Description
The present application will be described in further detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The technological progress makes the related technology put forward higher requirements on the quality of software, and the importance of effective use of the memory is becoming more and more significant. How to make the limited memory exert the maximum efficiency becomes an important problem for effectively utilizing and managing the memory. The memory out-of-range is an improper memory operation, which may not only damage other data in the program using the memory, but also may affect other running programs and even the whole system in serious cases.
In the related art, variable data are found in a static instrumentation stage in a symbol derivation mode according to an actual using mode, and whether memory access is out of range is determined based on the variable data, but the method has certain disadvantages: the operation of statically matching variable names depends on the rigor of matching logic, and the variable matching possibly cannot be accurately found, so that matching errors can be caused, border-crossing information cannot be checked, even abnormal conditions caused by error matching cannot pass through a normal compiling stage; only information that the program normally matches and is a relatively common use mode of the stack array and is used beyond the boundary can be collected.
Based on the problems existing in the existing memory boundary crossing monitoring method, the memory boundary crossing monitoring method is provided, and the technical problems and the defects which cannot be solved in the prior technical scheme can be solved.
Fig. 1 shows an optional first flowchart of the memory out-of-range monitoring method according to the embodiment of the present application, which will be described according to various steps.
Step S101, determining the running information of the source code.
In some embodiments, the determining, by the memory out-of-range monitoring device, the running information of the source code includes: determining at least one memory application message of a source code; the memory application information includes at least one of: the memory comprises a target memory, a memory block head address, a memory block length and a first address segment. The first address segment is determined by a memory block head address and a memory block length included in any one of the at least one memory application message. For example, the memory first address is 0x312050 corresponding to a memory length of 8, and the first address segment includes: 0x312050 to 0x 312057.
In some embodiments, the determining, by the memory boundary crossing monitor, the memory application information of the source code includes: in the process of static analysis of a source code, the memory out-of-range monitoring device sets a memory information recording function at the position of at least one memory application operation function in the source code; and in the executing process of the source code, the at least one memory information recording function records and stores at least one memory application information. The memory application information may further include at least one of: the memory application operation function, the file to which the function belongs and the line number of the function in the file.
In some embodiments, the determining, by the memory out-of-range monitoring device, the running information of the source code further includes: determining at least one memory use information of the source code based on the memory application information; the memory usage information at least comprises: the method comprises the steps of obtaining a data source memory, a first access address and the size of a residual memory; the first access address comprises a memory access address corresponding to any memory use information.
In some embodiments, the determining, by the memory out-of-range monitoring device, at least one memory usage information of the source code based on the memory application information includes: in the static analysis process of the source code, the memory out-of-range monitoring device sets at least one memory detection function at the position of at least one memory variable using operation in the source code; and in the executing process of the source code, the at least one memory detection function determines the size of a data source memory and the size of a target memory based on the at least one memory application message.
In some embodiments, the destination memory includes: in the process that the source code executes at least one memory application operation, the size of the memory applied by any memory application operation; the data source memory includes: in the running process of the source code, any memory variable uses the memory required by the data generated by the operation.
And step S102, confirming the out-of-range condition of the memory based on the data source memory in the operation information.
In some embodiments, the memory out-of-range monitoring device, based on the data source memory in the operation information, determining that the memory out-of-range condition includes: under the condition that a first access address exists in the memory application information, judging whether the size of the data source memory is larger than that of the target memory; and confirming that the memory access of the first access address is out of bounds under the condition that the size of the data source memory is larger than that of the target memory. Or, under the condition that the first access address does not exist in the memory application information, judging whether the first access address exists in a first address field in the memory application information or not; under the condition that the first access address exists in the first address field, judging whether the size of the data source memory is larger than the size of the residual memory; and confirming that the memory access of the first access address is out of bounds under the condition that the size of the data source memory is larger than the size of the residual memory. Or, confirming that the memory access of the first access address is out of bounds under the condition that the first access address does not exist in the first address field.
In some embodiments, the determining, by the memory boundary crossing monitor, a memory boundary crossing condition based on the data source memory in the operation information further includes: and under the condition that a first access address exists in the memory application information and the size of the data source memory is smaller than or equal to that of the target memory, confirming that the memory access of the first access address is not out of range. Or, under the condition that a first access address does not exist in the memory application information, the first access address exists in the first address field, and the size of the data source memory is smaller than or equal to the size of the residual memory, it is determined that the memory access of the first access address is not out of range.
In some embodiments, the method further comprises: and outputting the memory access boundary-crossing information.
In some embodiments, in a case that it is determined that the memory access of the first access address is out of bounds, the memory out-of-bounds monitoring apparatus classifies a function position corresponding to the memory access out-of-bounds operation, and outputs memory access out-of-bounds information.
Therefore, by the memory out-of-range monitoring method provided by the embodiment of the application, the memory application information and the memory use information of the source code are determined by determining the running information of the source code, and the size relationship between the data source memory and the target memory or the size relationship between the data source memory and the residual memory is determined by matching the memory block head address in the memory application information and the first access address in the memory use information, so as to judge whether the memory access of the first access address is out of range. And outputting the memory access boundary crossing information when the memory access boundary crossing is confirmed. The method and the device realize automatic detection of the memory boundary crossing and accurately position the specific position of the memory access boundary crossing, improve the stability and reliability of the source code and improve the software quality. Meanwhile, the memory out-of-bounds monitoring method provided by the embodiment of the application is not only suitable for out-of-bounds memory access, but also suitable for out-of-bounds memory access of the stack array, and particularly capable of detecting out-of-bounds memory access. The method has wider application range, and can accurately track the use condition of the memory for local pointer variables, pointer parameter transmission and the like; due to the uniqueness of the address, the accuracy of the address matching mode is high, and the condition of access boundary crossing can be detected more effectively.
Fig. 2 shows an optional flowchart for determining running information of a source code according to an embodiment of the present application, and fig. 3 shows an optional flowchart for a memory out-of-range monitoring method according to an embodiment of the present application, which will be described with reference to fig. 2 and fig. 3.
In step S201, a memory information recording function Zoafun1() is set.
In some embodiments, the setting of the memory information recording function Zoafun1() by the memory out-of-range monitoring device includes: and in the process of static analysis of the source code, matching the memory application function, and setting the memory information recording function Zoafun1() at the position where the function matching is successful.
In some embodiments, when the memory application mode is heap memory, the application functions of malloc (memoryallocation), NEW, or MMAP are matched, and the memory information recording function Zoafun1() is set at the position where the function matching is successful. The Malloc, the NEW and the MMAP are memory application methods, the Malloc and the NEW are dynamic memory application methods, and the MMAP is a method for mapping a file or other objects into a memory.
In other embodiments, when the memory application mode is a declaration mode of a stack array, the memory application function is matched, and the memory information recording function Zoafun1() is set at a position where the function matching is successful. The stack array declaration may include the way the array is defined in the function, such as int p [11 ].
In some embodiments, the memory information recording function Zoafun1() is configured to record memory application information, where the memory application information includes at least one of: the method comprises the steps of a target memory, a memory block head address, a memory block length, a first address field, a function of the memory application operation, a file to which the function belongs and a line number of the function in the file. And the memory information recording function records the memory application information and stores the memory application information into a memory information application record.
In some embodiments, the structure pseudo code of the memory information application record may be:
struct zoa_ptr_info
{
type ptr; recording application memory address
int size; recording the current memory application size
Other necessary information like function, file, line number, etc
};
In other embodiments, in the case that the memory application mode is a stack array declaration mode, the memory information recording function stores all stack memory addresses of one function in a structure of memory information application records different from the heap memory application mode, so that all stack memory application records of the function are released at one time when the function is ended.
In some embodiments, the structure pseudo code of the memory information application record may be:
key: combining information of functions into unique identification
Value: list < Stack array first Address >
In step S202, a memory detection function Zoafun2() is set.
In some embodiments, the setting of the memory crossing detection function Zoafun2() by the memory crossing monitor device includes: and in the process of executing the source code, matching a memory access function, and setting the memory detection function Zoafun2() at the position where the function matching is successful.
In some embodiments, in the case where the memory access mode is heap memory, the memory access function of memset (), memcopy (), memmevoe (), Strcpy (), strncpy () or Snprintf () is matched, and the memory detection function Zoafun2() is set at a position where the function matching is successful.
In other embodiments, when the memory access mode is a first address offset access of the stack array, the memory access function is matched, and the memory detection function Zoafun2() is set at a position where the function matching is successful.
In still other embodiments, the memory access mode is that in the case of memory access by the stack array through "[ ]", p [ ]ismatched, and the memory detection function Zoafun2() is set at the position where the function matching is successful.
The difference of the different access modes is that the incoming parameters are different, and the incoming parameters of the memory access mode can be the line number of the use function; the incoming parameter for the stack array access mode may be the row number of the stack array.
In some embodiments, the memory detection function Zoafun2() is configured to determine at least one memory usage information of the source code based on the memory application information; the memory usage information at least comprises: the method comprises the steps of obtaining a data source memory, a first access address and the size of a residual memory; the first access address comprises a memory access address corresponding to any memory use information.
In step S203, an information recording release function Zoafun3() is set.
In some embodiments, the setting of the information record release function Zoafun3() by the memory boundary crossing monitor device includes: and in the process of static analysis of the source code, matching a memory information removal function, and setting the information record release function Zoafun3() at the position where the function matching is successful.
In some embodiments, when the memory release mode is the heap memory, release functions of delete and free are matched, and the information record release function Zoafun3() is set at a position where the function matching is successful. The information record release function Zoafun3() is used to remove the memory application information corresponding to the memory release.
In other embodiments, in the case where the memory release manner is a declaration manner of the stack array, the information recording release function Zoafun3() is set at the end position of the program. And the information record release function Zoafun3() is used for removing all stack memory application records of the program.
Step S204, determining whether the memory application information includes the first access address.
In some embodiments, the determining, by the memory out-of-range monitoring device, whether the first access address exists in the memory application information includes: judging whether a first access address exists in at least one memory block initial address included in the memory application information, and executing step S207 under the condition that the first access address exists in the memory application information; if the first access address does not exist in the memory application information, step S205 is executed.
Step S205, determining whether the first access address exists in the first address field in the memory application information.
In some embodiments, the determining, by the memory out-of-range monitoring device, whether the first access address exists in the first address field in the memory application information includes: the memory out-of-range device judges whether the first access address exists in a first address segment between an initial address and an end address in the memory application information. Executing step S206 if the first access address exists in the first address segment; in case the first access address does not exist in the first address segment, step S208 is performed.
In some embodiments, the first address field includes an address field between an initial address and an end address in the memory application information. The first address segment is determined by a memory block head address and a memory block length included in any one of the at least one memory application message. For example, the memory first address is 0x312050 corresponding to a memory length of 8, and the first address segment includes: 0x312050 to 0x 312057; the initial address is 0x312050 and the end address is 0x 312057.
In step S206, it is determined whether the size of the data source memory is larger than the size of the remaining memory.
In some embodiments, the data source memory comprises: in the running process of the source code, any memory variable uses a memory required by data generated by operation; the remaining memory includes: and in the running process of the source code, the memory can be allocated.
In some embodiments, the determining, by the memory out-of-range monitoring device, whether the size of the data source memory is larger than the size of the remaining memory includes: the memory out-of-range monitoring device judges whether the memory required by the data generated by any memory variable using operation is larger than the memory which can be allocated in the running process of the source code. Executing step S208 when the size of the data source memory is larger than the size of the remaining memory; and under the condition that the size of the data source memory is smaller than or equal to the size of the residual memory, confirming that the memory access of the first access address is not out of range.
Fig. 4 shows a schematic diagram of the memory out-of-range monitoring method according to the embodiment of the present application, and will be described with reference to steps S201 to S206.
As shown in fig. 4, in the linked list storing the memory application information, the memory length corresponding to the memory with the memory first address of 0x312050 is 8, and further, the address segment corresponding to the memory with the memory first address of 0x312050 includes: 0x312050, 0x312051, 0x312052, 0x312053, 0x312054, 0x312055, and 0x312056, 0x 312057.
The memory detection function determines that the first access address is 0x312051, and if the length of the corresponding memory is 8, the memory detection function determines that the first access address does not exist in the memory application information through step S204, and then step S205 is executed. After step S205, it is determined that the first access address exists in the address segment corresponding to the memory with the memory first address of 0x312050, and step S206 is executed.
If 0x312051 is at the 2 nd bit in the address field, the memory first address is 0x312050 corresponding to memory length 8, then the residual memory size is 7, and the memory length required by first access address is 8, and the size (8) of data source memory is greater than the residual memory size (7), go to step S208.
Step S207, determine whether the size of the data source memory is larger than the size of the destination memory.
In some embodiments, the destination memory includes: and in the process of executing at least one memory application operation by the source code, the memory size applied by any memory application operation.
In some embodiments, the determining, by the memory out-of-range monitoring device, whether the size of the data source memory is larger than the size of the destination memory includes: the memory out-of-range monitoring device judges whether the memory required by the data generated by any memory variable using operation is larger than the memory size applied by any memory applying operation in the process of executing at least one memory applying operation by the source code; if the size of the data source memory is larger than that of the destination memory, step S208 is executed.
The following is further described with reference to steps S201 to S204, step S207, and fig. 4.
The memory detection function determines that the first access address is 0x312050, and if the corresponding memory length is 9, it is determined in step S204 that the first access address exists in the memory application information, and step S207 is performed. After step S207, the data source memory (9) with the memory first address of 0x312050 is determined to be larger than the destination memory (8), and step S208 is executed.
And step S208, outputting the memory access boundary crossing information.
In some embodiments, in a case that it is determined that the memory access of the first access address is out of bounds, the memory out-of-bounds monitoring apparatus classifies a function position corresponding to the memory access out-of-bounds operation, and outputs memory access out-of-bounds information.
The following is further described with reference to steps S201 to S205, step S208, and fig. 4.
The memory detection function determines that the first access address is 0x312058, and if the corresponding memory length is 8, it is determined in step S204 that the first access address does not exist in the memory application information, and step S205 is performed. Step S205 determines that the first access address does not exist in the address segment corresponding to the memory with the memory head address of 0x312058, step S208 is executed, border crossing access information is sent, the border crossing access information is collected and displayed, the collected data is stored and classified, and the specific code position of border crossing access and the information of memory access border crossing are visually displayed conveniently.
Therefore, by the memory out-of-range monitoring method provided by the embodiment of the application, the memory application information and the memory use information of the source code are determined by determining the running information of the source code, and the size relationship between the data source memory and the target memory or the size relationship between the data source memory and the residual memory is determined by matching the memory block head address in the memory application information and the first access address in the memory use information, so as to judge whether the memory access of the first access address is out of range. And outputting the memory access boundary crossing information when the memory access boundary crossing is confirmed. The method and the device realize automatic detection of the memory boundary crossing and accurately position the specific position of the memory access boundary crossing, improve the stability and reliability of the source code and improve the software quality. Meanwhile, the memory out-of-bounds monitoring method provided by the embodiment of the application is not only suitable for out-of-bounds memory access, but also suitable for out-of-bounds memory access of the stack array, and particularly capable of detecting out-of-bounds memory access. The method has wider application range, and can accurately track the use condition of the memory for local pointer variables, pointer parameter transmission and the like; due to the uniqueness of the address, the accuracy of the address matching mode is high, and the condition of access boundary crossing can be detected more effectively.
Fig. 5 is a schematic diagram illustrating an alternative structure of a memory out-of-range monitoring apparatus according to an embodiment of the present application, which will be described according to various parts.
In some embodiments, the memory out-of-range monitoring apparatus 300 includes a determination unit 301 and a confirmation unit 302.
The determining unit 301 is configured to determine running information of the source code.
In some embodiments, the determining unit 301 determines the running information of the source code, including: determining at least one memory application message of a source code; the memory application information includes at least one of: the memory comprises a target memory, a memory block head address, a memory block length and a first address segment. The first address segment is determined by a memory block head address and a memory block length included in any one of the at least one memory application message. For example, the memory first address is 0x312050 corresponding to a memory length of 8, and the first address segment includes: 0x312050 to 0x 312057.
In some embodiments, the determining unit 301 determines the memory application information of the source code, including: in the process of static analysis of the source code, the determining unit 301 sets a memory information recording function at the position of at least one memory application operation function in the source code; in the process of executing the source code, the determining unit 301 records and stores at least one memory application information. The memory application information may further include at least one of: the memory application operation function, the file to which the function belongs and the line number of the function in the file.
In some embodiments, the determining unit 301 determines the running information of the source code further includes: determining at least one memory use information of the source code based on the memory application information; the memory usage information at least comprises: the method comprises the steps of obtaining a data source memory, a first access address and the size of a residual memory; the first access address comprises a memory access address corresponding to any memory use information.
In some embodiments, the determining unit 301 determining at least one memory usage information of the source code based on the memory application information includes: in the process of static analysis of source code, the determining unit 301 sets at least one memory detection function in the location of at least one memory variable using operation in the source code; in the process of executing the source code, the determining unit 301 determines the size of the data source memory and the size of the destination memory based on the at least one memory application message.
In some embodiments, the destination memory includes: in the process that the source code executes at least one memory application operation, the size of the memory applied by any memory application operation; the data source memory includes: in the running process of the source code, any memory variable uses the memory required by the data generated by the operation.
The confirming unit 302 is configured to confirm a memory out-of-range condition based on the data source memory in the operation information.
In some embodiments, the memory out-of-range monitoring apparatus further includes a determining unit 303. The determining unit 303 is configured to determine whether the size of the data source memory is larger than that of the destination memory when the first access address exists in the memory application information; the memory access control device is used for judging whether a first access address exists in a first address field in the memory application information or not under the condition that the first access address does not exist in the memory application information; and under the condition that the first access address exists in the first address field, judging whether the size of the data source memory is larger than the size of the residual memory.
In some embodiments, when the first access address exists in the memory application information, the determining unit 303 determines whether the size of the data source memory is larger than the size of the destination memory; in a case that the size of the data source memory is larger than that of the destination memory, the determining unit 302 determines that the memory access of the first access address is out of bounds. Or, in the case that the first access address does not exist in the memory application information, the determining unit 303 determines whether the first access address exists in a first address field in the memory application information; when the first access address exists in the first address segment, the determining unit 303 determines whether the size of the data source memory is larger than the size of the remaining memory; in a case that the size of the data source memory is larger than the size of the remaining memory, the determining unit 302 determines that the memory access of the first access address is out of bounds. Alternatively, in a case that the first access address does not exist in the first address segment, the confirming unit 302 confirms that the memory access of the first access address is out of bounds.
In other embodiments, in a case that the memory application information includes a first access address and the size of the data source memory is smaller than or equal to the size of the destination memory, the determining unit 302 determines that the memory access of the first access address is not out of range. Or, the determining unit 302 determines that the memory access of the first access address is not out of bounds under the condition that the memory application information does not have a first access address, the first access address exists in the first address field, and the size of the data source memory is smaller than or equal to the size of the remaining memory.
In some embodiments, the memory boundary crossing apparatus 300 further includes an output unit 304 for outputting the memory access boundary crossing information.
In some embodiments, in the case that the memory access of the first access address is determined to be out of bounds, the output unit 304 classifies a function location corresponding to the memory access out of bounds operation, and outputs memory access out of bounds information.
Therefore, with the memory out-of-range monitoring device provided in this embodiment of the present application, the memory application information and the memory usage information of the source code are determined by determining the operation information of the source code, and the size relationship between the data source memory and the target memory, or the size relationship between the data source memory and the remaining memory, is determined by matching the memory block head address in the memory application information and the first access address in the memory usage information, so as to determine whether the memory access at the first access address is out of range. And outputting the memory access boundary crossing information when the memory access boundary crossing is confirmed. The method and the device realize automatic detection of the memory boundary crossing and accurately position the specific position of the memory access boundary crossing, improve the stability and reliability of the source code and improve the software quality. Meanwhile, the memory out-of-bounds monitoring method provided by the embodiment of the application is not only suitable for out-of-bounds memory access, but also suitable for out-of-bounds memory access of the stack array, and particularly capable of detecting out-of-bounds memory access. The method has wider application range, and can accurately track the use condition of the memory for local pointer variables, pointer parameter transmission and the like; due to the uniqueness of the address, the accuracy of the address matching mode is high, and the condition of access boundary crossing can be detected more effectively.
Fig. 6 is a schematic diagram of a hardware structure of an electronic device according to an embodiment of the present invention, in which the memory out-of-range monitoring apparatus 400 includes: at least one processor 401, memory 402, and at least one network interface 404. The various components of the memory boundary crossing monitor device 400 are coupled together by a bus system 405. It is understood that the bus system 405 is used to enable connection communication between these components. The bus system 405 includes a power bus, a control bus, and a status signal bus in addition to a data bus. For clarity of illustration, however, the various buses are labeled as bus system 405 in fig. 6.
It will be appreciated that the memory 402 can be either volatile memory or nonvolatile memory, and can include both volatile and nonvolatile memory. The nonvolatile Memory may be a ROM, a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), an Electrically Erasable Programmable Read-Only Memory (EEPROM), a magnetic Random access Memory (FRAM), a Flash Memory (Flash Memory), a magnetic surface Memory, an optical disc, or a compact disc Read-Only Memory (CD-ROM); the magnetic surface storage may be disk storage or tape storage. Volatile Memory can be Random Access Memory (RAM), which acts as external cache Memory. By way of illustration and not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Synchronous Static Random Access Memory (SSRAM), Dynamic Random Access Memory (DRAM), Synchronous Dynamic Random Access Memory (SDRAM), Double Data Rate Synchronous Dynamic Random Access Memory (DDRSDRAM), Enhanced Synchronous Dynamic Random Access Memory (Enhanced Synchronous Dynamic Random Access Memory, DRAM), Synchronous linked Dynamic Random Access Memory (SDRAM), Direct Memory Access (DRD) RAM, and the like. The memory 402 described in connection with the embodiments of the invention is intended to comprise, without being limited to, these and any other suitable types of memory.
The memory 402 in the embodiment of the present invention is used for storing various types of data to support the operation of the memory out-of-range monitoring apparatus 400. Examples of such data include: any computer program for operating on the memory out-of-range monitoring device 400, such as application 4022. A program for implementing the method according to the embodiment of the present invention may be included in the application 4022.
The method disclosed in the above embodiments of the present invention may be applied to the processor 401, or implemented by the processor 401. The processor 401 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 401. The Processor 401 described above may be a general purpose Processor, a Digital Signal Processor (DSP), or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. Processor 401 may implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present invention. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed by the embodiment of the invention can be directly implemented by a hardware decoding processor, or can be implemented by combining hardware and software modules in the decoding processor. The software modules may be located in a storage medium located in the memory 402, and the processor 401 reads the information in the memory 402 and performs the steps of the aforementioned methods in conjunction with its hardware.
In an exemplary embodiment, the memory out-of-range monitoring apparatus 400 may be implemented by one or more Application Specific Integrated Circuits (ASICs), DSPs, Programmable Logic Devices (PLDs), Complex Programmable Logic Devices (CPLDs), FPGAs, general purpose processors, controllers, MCUs, MPUs, or other electronic components for performing the aforementioned methods.
The embodiment of the application also provides a storage medium for storing the computer program.
Optionally, the storage medium may be applied to the terminal device in the embodiment of the present application, and the computer program enables the computer to execute corresponding processes in each method in the embodiment of the present application, which is not described herein again for brevity.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above description is only exemplary of the present invention and should not be taken as limiting the scope of the present invention, and any modifications, equivalents, improvements, etc. that are within the spirit and principle of the present invention should be included in the present invention.

Claims (12)

1. A memory out-of-range monitoring method is characterized by comprising the following steps:
determining running information of the source code;
and confirming the out-of-range condition of the memory based on the data source memory in the operation information.
2. The method of claim 1, wherein determining the running information of the source code comprises:
determining memory application information of a source code;
the memory application information includes at least one of: the memory comprises a target memory, a memory block head address and a first address field.
3. The method of claim 2, wherein determining the running information of the source code comprises:
determining the memory use information of the source code based on the memory application information;
the memory usage information at least comprises: the data source memory, the first access address and the size of the residual memory.
4. The method according to any one of claims 1 to 3, wherein the determining a memory out-of-range condition based on the data source memory in the source code run information comprises:
under the condition that a first access address exists in the memory application information, judging whether the size of the data source memory is larger than that of the target memory;
and confirming that the memory access of the first access address is out of bounds under the condition that the size of the data source memory is larger than that of the target memory.
5. The method according to any one of claims 1 to 3, wherein the determining a memory out-of-range condition based on the data source memory in the source code run information comprises:
under the condition that a first access address does not exist in the memory application information, judging whether the first access address exists in a first address field in the memory application information or not;
under the condition that the first access address exists in the first address field, judging whether the size of the data source memory is larger than the size of the residual memory;
confirming that the memory access of the first access address is out of bounds under the condition that the size of the data source memory is larger than the size of the residual memory; or, confirming that the memory access of the first access address is out of bounds under the condition that the first access address does not exist in the first address field.
6. A memory out-of-range monitoring device, the device comprising:
the determining unit is used for determining the running information of the source code;
and the confirming unit is used for confirming the out-of-range condition of the memory based on the data source memory in the operation information.
7. The apparatus of claim 6, wherein the determining means is further configured to:
determining memory application information of a source code;
the memory application information includes at least one of: the memory comprises a target memory, a memory block head address and a first address field.
8. The apparatus of claim 7, wherein the determining means is further configured to:
determining the memory use information of the source code based on the memory application information;
the memory usage information at least comprises: the data source memory, the first access address and the size of the residual memory.
9. The apparatus of any one of claims 6 to 8, further comprising:
the judging unit is used for judging whether the size of the data source memory is larger than that of the target memory under the condition that the first access address exists in the memory application information;
the confirming device is further configured to confirm that the memory access of the first access address is out of bounds when the size of the data source memory is larger than the size of the destination memory.
10. The apparatus of any one of claims 6 to 8, further comprising:
the judging unit is used for judging whether a first access address exists in a first address field in the memory application information under the condition that the first access address does not exist in the memory application information; under the condition that the first access address exists in the first address field, judging whether the size of the data source memory is larger than the size of the residual memory;
the confirming unit is further configured to confirm that the memory access of the first access address is out of bounds when the size of the data source memory is larger than the size of the remaining memory; or, confirming that the memory access of the first access address is out of bounds under the condition that the first access address does not exist in the first address field.
11. A storage medium storing an executable program, wherein the executable program, when executed by a processor, implements the memory out-of-range monitoring method of any one of claims 1 to 5.
12. A memory out-of-range monitoring device comprising a memory, a processor and an executable program stored on the memory and executable by the processor, wherein the processor executes the executable program to perform the steps of the memory out-of-range monitoring method according to any one of claims 1 to 5.
CN202010099362.6A 2020-02-18 2020-02-18 Memory out-of-range monitoring method and device and storage medium Pending CN111338794A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010099362.6A CN111338794A (en) 2020-02-18 2020-02-18 Memory out-of-range monitoring method and device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010099362.6A CN111338794A (en) 2020-02-18 2020-02-18 Memory out-of-range monitoring method and device and storage medium

Publications (1)

Publication Number Publication Date
CN111338794A true CN111338794A (en) 2020-06-26

Family

ID=71183553

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010099362.6A Pending CN111338794A (en) 2020-02-18 2020-02-18 Memory out-of-range monitoring method and device and storage medium

Country Status (1)

Country Link
CN (1) CN111338794A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113672237A (en) * 2021-09-03 2021-11-19 支付宝(杭州)信息技术有限公司 Program compiling method and device for preventing memory boundary crossing

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101561775A (en) * 2009-05-12 2009-10-21 华为技术有限公司 Method and device for monitoring memory
CN105988921A (en) * 2015-02-06 2016-10-05 中兴通讯股份有限公司 Method and device for detecting out of range problem of memory
WO2016173172A1 (en) * 2015-04-29 2016-11-03 中兴通讯股份有限公司 Method and apparatus for detecting heap memory operation
CN110413521A (en) * 2019-07-24 2019-11-05 杭州迪普信息技术有限公司 A kind of the write-overflow detection method and device of heap memory

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101561775A (en) * 2009-05-12 2009-10-21 华为技术有限公司 Method and device for monitoring memory
CN105988921A (en) * 2015-02-06 2016-10-05 中兴通讯股份有限公司 Method and device for detecting out of range problem of memory
WO2016173172A1 (en) * 2015-04-29 2016-11-03 中兴通讯股份有限公司 Method and apparatus for detecting heap memory operation
CN110413521A (en) * 2019-07-24 2019-11-05 杭州迪普信息技术有限公司 A kind of the write-overflow detection method and device of heap memory

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113672237A (en) * 2021-09-03 2021-11-19 支付宝(杭州)信息技术有限公司 Program compiling method and device for preventing memory boundary crossing
CN113672237B (en) * 2021-09-03 2022-03-11 支付宝(杭州)信息技术有限公司 Program compiling method and device for preventing memory boundary crossing

Similar Documents

Publication Publication Date Title
US8291379B2 (en) Runtime analysis of a computer program to identify improper memory accesses that cause further problems
WO2016123908A1 (en) Memory overflow detection method and apparatus
CN109960932B (en) File detection method and device and terminal equipment
CN107590016B (en) Power-down restarting identification method and device
CN110727597A (en) Method for completing use case based on log troubleshooting invalid codes
CN114090379A (en) Server bus fault positioning method and device, electronic equipment and storage medium
US8788891B2 (en) Bitline deletion
CN111338794A (en) Memory out-of-range monitoring method and device and storage medium
US8489938B2 (en) Diagnostic data capture in a computing environment
CN111338864B (en) Memory problem detection method, device, computer equipment and storage medium
CN104239201A (en) Memory read-write monitoring method in flexible single-step system
CN111813748B (en) File system mounting method and device, electronic equipment and storage medium
CN112650613B (en) Error information processing method and device, electronic equipment and storage medium
CN110659194A (en) Dynamic memory detection method, device and storage medium
CN110750375B (en) Embedded equipment and abnormal information processing method thereof
CN110765493B (en) File baseline defense method and device based on Linux pre-link and storage equipment
CN113612661A (en) Method, device, computing equipment and storage medium for checking program stability
CN111221737B (en) Coverage rate determining method, coverage rate determining device and storage medium
KR101346809B1 (en) Method and appratus for protecting integrity of log file
US20070179635A1 (en) Method and article of manufacure to persistently deconfigure connected elements
CN118227486A (en) Release version debugging method, release version debugging device, electronic device and storage medium
CN116149577B (en) Data processing method, system and readable storage medium based on rotary pool
JPH06266573A (en) Fault recovery information managing system
CN110990265A (en) Coverage rate determining method and device and storage medium
CN109656580B (en) Serial-port NAND FLASH data zero clearing processing method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination