WO2016123908A1 - Memory overflow detection method and apparatus - Google Patents

Memory overflow detection method and apparatus Download PDF

Info

Publication number
WO2016123908A1
WO2016123908A1 PCT/CN2015/084147 CN2015084147W WO2016123908A1 WO 2016123908 A1 WO2016123908 A1 WO 2016123908A1 CN 2015084147 W CN2015084147 W CN 2015084147W WO 2016123908 A1 WO2016123908 A1 WO 2016123908A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory
detected
program
address
memory block
Prior art date
Application number
PCT/CN2015/084147
Other languages
French (fr)
Chinese (zh)
Inventor
赵东林
Original Assignee
中兴通讯股份有限公司
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 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2016123908A1 publication Critical patent/WO2016123908A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software

Definitions

  • the invention relates to the field of memory management and memory detection of an embedded system, in particular to a method and device for detecting a memory out of bounds.
  • the embodiment of the invention provides a method and a device for detecting a memory out of bounds, so as to at least solve the problem that the memory access is difficult to locate beyond the boundary in the related art.
  • a method for detecting a memory out of bounds including:
  • the release flag indicates that the memory block is not released, obtaining a first bias address of the to-be-detected program, where the first bias address is a bias address farthest from the start address;
  • the first biased address falls within the memory range of the memory block; if the first biased address does not fall within the memory range of the memory block, it is determined that the memory of the program to be detected is out of bounds.
  • the method further includes:
  • a memory block is requested according to the operation information included in the program to be detected.
  • the method further includes:
  • the memory block is operated according to the operation information included in the program to be detected.
  • the method further includes:
  • the method further includes:
  • step of obtaining the start address and the memory management header information of the memory block allocated to the program to be detected includes:
  • a memory out-of-band detection apparatus including:
  • a first obtaining module configured to obtain a starting address and a memory management header information of a memory block allocated to the program to be detected, where the memory management header information includes: a capacity of the memory block and a release flag;
  • the first detecting module is configured to detect a release flag, and if the release flag indicates that the memory block has been released, determining that the memory to be detected is out of bounds;
  • a second obtaining module configured to: when the release flag indicates that the memory block is not released, acquire a first bias address of the to-be-detected program, where the first bias address is a bias address farthest from the start address;
  • the second detecting module is configured to detect, according to the capacity and the starting address of the memory block, whether the first biasing address falls within the memory range of the memory block; if the first biasing address does not fall within the memory range of the memory block, determining The detection program has a memory out of bounds.
  • the detecting device that the memory is out of bounds further includes:
  • the application module is configured to apply for a memory block according to the operation information included in the program to be detected.
  • the detecting device that the memory is out of bounds further includes:
  • the operation module is configured to operate the memory block according to the operation information included in the program to be detected.
  • the detecting device that the memory is out of bounds further includes:
  • the processing module is configured to record the program to be detected that the memory is out of bounds, and suspend the process of executing the program to be detected.
  • the detecting device that the memory is out of bounds further includes:
  • the extension module is set to obtain the input processing strategy and perform corresponding operations according to the processing policy.
  • the first obtaining module includes:
  • a receiving unit configured to receive a memory management header address of the program to be detected
  • the obtaining unit is configured to search for a starting address of the memory block according to the memory management head address, and read the memory management header information stored in the memory block management header address.
  • the beneficial effects of the embodiment of the present invention are: a method and device for detecting a memory out of bounds, by detecting the legality of a memory block of the program to be detected first, and then detecting whether the program to be detected all falls within the legal range of the memory block, thereby detecting Whether the program to be detected has a memory out of bounds, realizing rapid positioning of the memory out of bounds, improving the fault tolerance, reliability and usability of the entire system executing the program to be detected.
  • FIG. 1 is a schematic flow chart 1 of a method for detecting a memory out of bounds according to the present invention
  • FIG. 2 is a schematic flow chart 2 of a method for detecting a memory out of bounds according to the present invention
  • Fig. 3 is a block diagram showing the apparatus for detecting a memory out of bounds according to the present invention.
  • 101 a first acquisition module, 102, a second detection module, 103, a second acquisition module, 104, a second detection module.
  • an embodiment of the present invention provides a memory out-of-bounds detection method, which can detect whether the program has a memory out of bounds after each program is executed, and A program that has a memory out of bounds is recorded.
  • the detection method includes:
  • Step 10 Obtain a start address and a memory management header information of a memory block allocated to the program to be detected, and the memory management header information includes: a capacity of the memory block and a release flag.
  • a program to be detected needs to be detected whether it has a memory out of bounds, it is necessary to acquire the starting address of the memory block allocated by the system to the program to be detected and the memory management header information of the memory block.
  • the system allocates a memory block for the to-be-detected program, the start address of the memory block and the memory management header address are recorded, so that it is necessary to detect whether the program to be detected has a memory out of bounds problem.
  • the capacity of the memory block and the release flag are recorded in the memory management header information.
  • the memory block capacity is the memory block size.
  • the start address of the memory block is known, the end address of the memory block can be obtained according to the size of the memory block.
  • the release flag indicates whether the memory block is released.
  • the meaning of the code can be customized. For example, all "1" indicates that it has not been released, and all "0" indicates that it has been released.
  • Step 20 Detect the release flag. If the release flag indicates that the memory block has been released, it is determined that the memory to be detected is out of bounds.
  • a release flag in the memory management header information of the memory block corresponding to the program to be detected is required, and if the release flag indicates that the memory block has been released, the release flag is released.
  • all "0" is used, it indicates that the memory block has been released, and the memory block is illegal, but is still occupied by the program to be detected, indicating that the memory of the program to be detected has an out of bounds.
  • Step 30 If the release flag indicates that the memory block is not released, the first bias address of the program to be detected is obtained, and the first bias address is a bias address farthest from the start address.
  • the release flag indicates that the memory block is not released, that is, the release flag is all "1"
  • the program to be detected can occupy or rewrite it.
  • the system records each of the bias addresses, so the distance from the start address can be selected.
  • the farthest bias address is the first bias address.
  • Step 40 Detect whether the first bias address falls within the memory range of the memory block according to the capacity and the starting address of the memory block; if the first bias address does not fall within the memory range of the memory block, determine that the program to be detected generates memory. Cross the border.
  • Step 10 has obtained the capacity and the starting address of the memory block, so that the memory range of the memory block is known, and the first bias address obtained in the detecting step 30 falls within the memory range of the memory block, if the first biased address does not fall.
  • the first bias address is not between the start address and the end address, it is determined that the memory out of bounds problem occurs in the to-be-detected program. If the first biased address falls within the memory range of the memory block, that is, the first biased address is between the start address and the end address, it is determined that the memory out of bounds problem does not occur in the to-be-detected program, and then the corresponding indication may be made according to the system indication. action.
  • the detecting method further includes:
  • Step 01 Apply for a memory block according to the operation information included in the program to be detected.
  • the operation information included in the program to be detected refers to the code information of the program to be detected, and the system can allocate a reasonable memory block according to the code information.
  • the application process can call the memory application function. When the system allocates a memory block that can be used, it also returns the memory block start address and the memory management header address.
  • the detecting method further includes:
  • Step 02 The memory block is operated according to the operation information included in the program to be detected.
  • the segment program may be processed according to a preset processing strategy, for example, the program to be detected is recorded, and the execution of the to-be-detected program is suspended. process.
  • the processing strategy for what kind of processing is performed on the segment program may be customized, and the to-be-detected program is correspondingly operated according to the input processing strategy.
  • a mature reserved command line may be adopted.
  • step 10 includes:
  • the general memory management header address is the previous address of the memory block start address.
  • the start address of the memory block can be obtained.
  • the memory management head address and the memory block start address recorded in the system can also be directly read.
  • a memory management header information is recorded in the memory management header address, and the size of the corresponding memory block is recorded in the memory management header information, and a release flag of whether the memory block is released.
  • the memory out-of-bounds detection method of the present invention detects the legality of the memory block of the program to be detected, and then detects whether the program to be detected all falls within the legal range of the memory block, thereby detecting whether the program to be detected has a memory out of bounds, and realizing The fast positioning of the memory out of bounds improves the fault tolerance, reliability and availability of the entire system executing the program to be tested.
  • a device for detecting an out-of-band memory includes:
  • the first obtaining module 101 is configured to obtain a starting address of the memory block allocated to the program to be detected and memory management header information, where the memory management header information includes: a capacity of the memory block and a release flag;
  • the first detecting module 102 is configured to detect a release flag, and if the release flag indicates that the memory block has been released, determining that the memory to be detected is out of bounds;
  • the second obtaining module 103 is configured to: when the release flag indicates that the memory block is not released, acquire a first bias address of the to-be-detected program, where the first bias address is a bias address farthest from the start address;
  • the second detecting module 104 is configured to detect, according to the capacity and the starting address of the memory block, whether the first biasing address falls within the memory range of the memory block; if the first biasing address does not fall within the memory range of the memory block, determining The memory of the program to be tested is out of bounds.
  • the detecting device that the memory is out of bounds further includes:
  • the application module is configured to apply for a memory block according to the operation information included in the program to be detected.
  • the detecting device that the memory is out of bounds further includes:
  • the operation module is configured to operate the memory block according to the operation information included in the program to be detected.
  • the detecting device that the memory is out of bounds further includes:
  • the processing module is configured to record the program to be detected that the memory is out of bounds, and suspend the process of executing the program to be detected.
  • the detecting device that the memory is out of bounds further includes:
  • the extension module is set to obtain the input processing strategy and perform corresponding operations according to the processing policy.
  • the first obtaining module includes:
  • a receiving unit configured to receive a memory management header address of the program to be detected
  • the obtaining unit is configured to search for a starting address of the memory block according to the memory management head address, and read the memory management header information stored in the memory block management header address.
  • the device is a device corresponding to the above-mentioned memory out-of-band detection method. All the implementation manners in the foregoing method embodiments are applicable to the device embodiment, and the same technical effects can be achieved.
  • the method and apparatus for detecting out-of-memory of the memory provided by the embodiment of the present invention have the following beneficial effects: realizing rapid positioning of memory out of bounds, improving fault tolerance, reliability, and availability of the entire system for executing the program to be detected. .

Landscapes

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

Abstract

A memory overflow detection method and apparatus, the method comprising: obtaining a starting address and memory management header information of a memory block allocated to a program to be detected, the memory management header information comprising a capacity and a releasing identifier of the memory block (S10); checking the releasing identifier, and if the releasing identifier indicates that the memory block has been released, determining that the program to be detected has memory overflow (S20); if the releasing identifier indicates that the memory block has not been released, obtaining a first deviation address of the program to be detected, the first deviation address being the deviation address furthest away from the starting address (S30); according to the capacity and the starting address of the memory block, detecting whether the first deviation address falls within a memory range of the memory block; if not, determining that the program to be detected has memory overflow (S40). By checking the validity of the memory block, then detecting whether all of the program to be detected falls within a valid range of the memory block, the method and apparatus detect whether the program has memory overflow, quickly locating a memory overflow.

Description

一种内存越界的检测方法及装置Method and device for detecting memory out of bounds 技术领域Technical field
本发明涉及嵌入式系统内存管理及内存检测领域,尤其涉及一种内存越界的检测方法及装置。The invention relates to the field of memory management and memory detection of an embedded system, in particular to a method and device for detecting a memory out of bounds.
背景技术Background technique
在嵌入式系统中,内存访问越界是一种常见错误,但在发生此类问题时,确认其源头极其困难;现有技术中对于检测内存越界问题,通过在内存尾部和头部添加用于记录内存申请释放情况的部分信息,在内存越界写到尾部或者头部时,能够通过检测尾部和头部的内容能够检测内存被越界访问。但是此类技术的缺陷在于,当某个模块使用的内存被其他模块改写时,如野指针,此种方法无法检测出。In embedded systems, memory access violations are a common mistake, but it is extremely difficult to confirm the source when such problems occur; in the prior art, to detect memory out of bounds, by adding a record for the end of the memory and the header Part of the information about the memory application release condition can detect that the memory is out of bounds by detecting the contents of the tail and the header when the memory is written to the tail or the header. However, the drawback of this type of technology is that when the memory used by a module is overwritten by another module, such as a wild pointer, this method cannot be detected.
发明内容Summary of the invention
本发明实施例提供了一种内存越界的检测方法及装置,以至少解决相关技术中内存访问越界难以定位的问题。The embodiment of the invention provides a method and a device for detecting a memory out of bounds, so as to at least solve the problem that the memory access is difficult to locate beyond the boundary in the related art.
依据本发明实施例的一个方面,提供了一种内存越界的检测方法,包括:According to an aspect of an embodiment of the present invention, a method for detecting a memory out of bounds is provided, including:
获取分配给待检测程序的内存块的起始地址和内存管理头信息,内存管理头信息包括:内存块的容量以及释放标记;Obtaining a starting address and a memory management header information of the memory block allocated to the program to be detected, where the memory management header information includes: a capacity of the memory block and a release flag;
检测释放标记,若释放标记指示内存块已被释放,则判断待检测程序发生内存越界;Detecting the release flag, and if the release flag indicates that the memory block has been released, determining that the memory to be detected is out of bounds;
若释放标记指示内存块未被释放,则获取待检测程序的第一偏向地址,第一偏向地址为距起始地址最远的偏向地址;If the release flag indicates that the memory block is not released, obtaining a first bias address of the to-be-detected program, where the first bias address is a bias address farthest from the start address;
根据内存块的容量和起始地址,检测第一偏向地址是否落在内存块的内存范围内;若第一偏向地址未落在内存块的内存范围内,则判断待检测程序发生内存越界。Depending on the capacity of the memory block and the starting address, it is detected whether the first biased address falls within the memory range of the memory block; if the first biased address does not fall within the memory range of the memory block, it is determined that the memory of the program to be detected is out of bounds.
进一步地,在获取分配给待检测程序的内存块的起始地址和内存管理头信息的步骤之前,还包括:Further, before the step of acquiring the start address and the memory management header information of the memory block allocated to the program to be detected, the method further includes:
根据待检测程序所包含的操作信息申请一内存块。 A memory block is requested according to the operation information included in the program to be detected.
进一步地,在获取分配给待检测程序的内存块的起始地址和内存管理头信息的步骤之后,还包括:Further, after the step of acquiring the start address and the memory management header information of the memory block allocated to the program to be detected, the method further includes:
根据待检测程序所包含的操作信息对内存块进行操作。The memory block is operated according to the operation information included in the program to be detected.
进一步地,在判断待检测程序发生内存越界的步骤之后,还包括:Further, after the step of determining that the memory of the to-be-detected program is out of bounds, the method further includes:
记录发生内存越界的待检测程序,并挂起执行待检测程序的进程。Record the program to be detected where the memory is out of bounds, and suspend the process of executing the program to be tested.
进一步地,在判断待检测程序发生内存越界的步骤之后,还包括:Further, after the step of determining that the memory of the to-be-detected program is out of bounds, the method further includes:
获取输入的处理策略,并根据处理策略对待检测程序进行相应操作。Obtain the input processing strategy and perform corresponding operations according to the processing policy.
进一步地,获取分配给待检测程序的内存块的起始地址和内存管理头信息的步骤包括:Further, the step of obtaining the start address and the memory management header information of the memory block allocated to the program to be detected includes:
接收待检测程序的内存管理头地址;Receiving a memory management header address of the program to be detected;
根据内存管理头地址查找内存块的起始地址,并读取存储在内存块管理头地址上的内存管理头信息。Find the starting address of the memory block according to the memory management header address, and read the memory management header information stored in the memory block management header address.
依据本发明实施例的另一个方面,还提供了一种内存越界的检测装置,包括:According to another aspect of the embodiments of the present invention, a memory out-of-band detection apparatus is further provided, including:
第一获取模块,设置为获取分配给待检测程序的内存块的起始地址和内存管理头信息,内存管理头信息包括:内存块的容量以及释放标记;a first obtaining module, configured to obtain a starting address and a memory management header information of a memory block allocated to the program to be detected, where the memory management header information includes: a capacity of the memory block and a release flag;
第一检测模块,设置为检测释放标记,若释放标记指示内存块已被释放,则判断待检测程序发生内存越界;The first detecting module is configured to detect a release flag, and if the release flag indicates that the memory block has been released, determining that the memory to be detected is out of bounds;
第二获取模块,设置为当释放标记指示内存块未被释放时,获取待检测程序的第一偏向地址,第一偏向地址为距起始地址最远的偏向地址;a second obtaining module, configured to: when the release flag indicates that the memory block is not released, acquire a first bias address of the to-be-detected program, where the first bias address is a bias address farthest from the start address;
第二检测模块,设置为根据内存块的容量和起始地址,检测第一偏向地址是否落在内存块的内存范围内;若第一偏向地址未落在内存块的内存范围内,则判断待检测程序发生内存越界。The second detecting module is configured to detect, according to the capacity and the starting address of the memory block, whether the first biasing address falls within the memory range of the memory block; if the first biasing address does not fall within the memory range of the memory block, determining The detection program has a memory out of bounds.
进一步地,该内存越界的检测装置还包括:Further, the detecting device that the memory is out of bounds further includes:
申请模块,设置为根据待检测程序所包含的操作信息申请一内存块。The application module is configured to apply for a memory block according to the operation information included in the program to be detected.
进一步地,该内存越界的检测装置还包括: Further, the detecting device that the memory is out of bounds further includes:
操作模块,设置为根据待检测程序所包含的操作信息对内存块进行操作。The operation module is configured to operate the memory block according to the operation information included in the program to be detected.
进一步地,该内存越界的检测装置还包括:Further, the detecting device that the memory is out of bounds further includes:
处理模块,设置为记录发生内存越界的待检测程序,并挂起执行待检测程序的进程。The processing module is configured to record the program to be detected that the memory is out of bounds, and suspend the process of executing the program to be detected.
进一步地,该内存越界的检测装置还包括:Further, the detecting device that the memory is out of bounds further includes:
扩展模块,设置为获取输入的处理策略,并根据处理策略对待检测程序进行相应操作。The extension module is set to obtain the input processing strategy and perform corresponding operations according to the processing policy.
进一步地,第一获取模块包括:Further, the first obtaining module includes:
接收单元,设置为接收待检测程序的内存管理头地址;a receiving unit, configured to receive a memory management header address of the program to be detected;
获取单元,设置为根据内存管理头地址查找内存块的起始地址,并读取存储在内存块管理头地址上的内存管理头信息。The obtaining unit is configured to search for a starting address of the memory block according to the memory management head address, and read the memory management header information stored in the memory block management header address.
本发明实施例的有益效果是:一种内存越界的检测方法及装置,通过先检测待检测程序的内存块的合法性,再检测待检测程序是否全部落在内存块的合法范围内,来检测该待检测程序是否发生内存越界,实现了内存越界的快速定位,提高了整个执行该待检测程序的系统的容错性、可靠性和可用性。The beneficial effects of the embodiment of the present invention are: a method and device for detecting a memory out of bounds, by detecting the legality of a memory block of the program to be detected first, and then detecting whether the program to be detected all falls within the legal range of the memory block, thereby detecting Whether the program to be detected has a memory out of bounds, realizing rapid positioning of the memory out of bounds, improving the fault tolerance, reliability and usability of the entire system executing the program to be detected.
附图说明DRAWINGS
图1表示本发明内存越界的检测方法的流程示意图一;1 is a schematic flow chart 1 of a method for detecting a memory out of bounds according to the present invention;
图2表示本发明内存越界的检测方法的流程示意图二;2 is a schematic flow chart 2 of a method for detecting a memory out of bounds according to the present invention;
图3表示本发明内存越界的检测装置的模块示意图。Fig. 3 is a block diagram showing the apparatus for detecting a memory out of bounds according to the present invention.
其中图中:101、第一获取模块,102、第二检测模块,103、第二获取模块,104、第二检测模块。In the figure: 101, a first acquisition module, 102, a second detection module, 103, a second acquisition module, 104, a second detection module.
具体实施方式detailed description
下面将参照附图更详细地描述本发明的示例性实施例。虽然附图中显示了本发明的示例性实施例,然而应当理解,可以以各种形式实现本发明而不应被这里阐述的实 施例所限制。相反,提供这些实施例是为了能够更透彻地理解本发明,并且能够将本发明的范围完整的传达给本领域的技术人员。Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the drawings, it should be understood that the invention may be The restrictions are imposed by the regulations. Rather, these embodiments are provided so that this invention may be more fully understood and the scope of the invention can be fully conveyed by those skilled in the art.
为了解决嵌入式系统内存越界难以定位的问题,如图1所示,本发明的实施例提供了一种内存越界的检测方法,可在每一段程序执行后检测该程序是否发生内存越界,并将发生内存越界的程序记录下来。该检测方法包括:In order to solve the problem that the embedded system memory is difficult to locate, as shown in FIG. 1 , an embodiment of the present invention provides a memory out-of-bounds detection method, which can detect whether the program has a memory out of bounds after each program is executed, and A program that has a memory out of bounds is recorded. The detection method includes:
步骤10:获取分配给待检测程序的内存块的起始地址和内存管理头信息,内存管理头信息包括:内存块的容量以及释放标记。Step 10: Obtain a start address and a memory management header information of a memory block allocated to the program to be detected, and the memory management header information includes: a capacity of the memory block and a release flag.
当某一待检测程序需要被检测其是否发生内存越界时,需要获取系统分配给该待检测程序的内存块的起始地址和该内存块的内存管理头信息。其中,当系统为该待检测程序分配内存块时,会记录该内存块的起始地址以及内存管理头地址,以便后续需要检测该待检测程序是否发生内存越界问题。在该内存管理头信息中记录有该内存块的容量以及释放标记。其中,内存块容量即内存块大小,当知道内存块的起始地址时,根据内存块大小就可得到内存块的终止地址。释放标记表示该内存块是否被释放的标记,通常可自定义其代码含义,例如:全“1”表示未被释放,全“0”表示已被释放。When a program to be detected needs to be detected whether it has a memory out of bounds, it is necessary to acquire the starting address of the memory block allocated by the system to the program to be detected and the memory management header information of the memory block. When the system allocates a memory block for the to-be-detected program, the start address of the memory block and the memory management header address are recorded, so that it is necessary to detect whether the program to be detected has a memory out of bounds problem. The capacity of the memory block and the release flag are recorded in the memory management header information. The memory block capacity is the memory block size. When the start address of the memory block is known, the end address of the memory block can be obtained according to the size of the memory block. The release flag indicates whether the memory block is released. Generally, the meaning of the code can be customized. For example, all "1" indicates that it has not been released, and all "0" indicates that it has been released.
步骤20:检测释放标记,若释放标记指示内存块已被释放,则判断待检测程序发生内存越界。Step 20: Detect the release flag. If the release flag indicates that the memory block has been released, it is determined that the memory to be detected is out of bounds.
当检测该待检测程序是否发生内存越界问题时,首先需要对该待检测程序对应的内存块的内存管理头信息中的释放标记,若该释放标记表示该内存块已被释放,即该释放标记为全“0”时,表示该内存块已被释放,该内存块为非法的,但仍被待检测程序占用,则说明该待检测程序发生了内存越界。When detecting whether the program to be detected has a memory out of bounds problem, firstly, a release flag in the memory management header information of the memory block corresponding to the program to be detected is required, and if the release flag indicates that the memory block has been released, the release flag is released. When all "0" is used, it indicates that the memory block has been released, and the memory block is illegal, but is still occupied by the program to be detected, indicating that the memory of the program to be detected has an out of bounds.
步骤30:若释放标记指示内存块未被释放,则获取待检测程序的第一偏向地址,第一偏向地址为距起始地址最远的偏向地址。Step 30: If the release flag indicates that the memory block is not released, the first bias address of the program to be detected is obtained, and the first bias address is a bias address farthest from the start address.
若该释放标记表示该内存块未被释放,即该释放标记为全“1”时,表示该内存块未被释放,该内存块为合法区域,待检测程序可对其占用或改写。这时需要通过检测待检测程序执行时的距起始地址最远的第一偏向地址来进行判断,在该待检测程序执行时,系统会记录其每个偏向地址,故可筛选距起始地址最远的偏向地址为第一偏向地址。 If the release flag indicates that the memory block is not released, that is, the release flag is all "1", it indicates that the memory block is not released, and the memory block is a legal area, and the program to be detected can occupy or rewrite it. At this time, it is necessary to determine the first bias address that is farthest from the start address when the program to be detected is executed. When the program to be detected is executed, the system records each of the bias addresses, so the distance from the start address can be selected. The farthest bias address is the first bias address.
步骤40:根据内存块的容量和起始地址,检测第一偏向地址是否落在内存块的内存范围内;若第一偏向地址未落在内存块的内存范围内,则判断待检测程序发生内存越界。Step 40: Detect whether the first bias address falls within the memory range of the memory block according to the capacity and the starting address of the memory block; if the first bias address does not fall within the memory range of the memory block, determine that the program to be detected generates memory. Cross the border.
步骤10已获取到内存块的容量和起始地址,这样可知内存块的内存范围,检测步骤30获取到的第一偏向地址是否落在该内存块的内存范围内,若第一偏向地址未落在内存块的内存范围内,即第一偏向地址不在起始地址和终止地址之间,则判断该待检测程序发生了内存越界问题。若第一偏向地址落在内存块的内存范围内,即第一偏向地址在起始地址和终止地址之间,则判断该待检测程序未发生内存越界问题,这时可根据系统指示做出相应动作。Step 10 has obtained the capacity and the starting address of the memory block, so that the memory range of the memory block is known, and the first bias address obtained in the detecting step 30 falls within the memory range of the memory block, if the first biased address does not fall. In the memory range of the memory block, that is, the first bias address is not between the start address and the end address, it is determined that the memory out of bounds problem occurs in the to-be-detected program. If the first biased address falls within the memory range of the memory block, that is, the first biased address is between the start address and the end address, it is determined that the memory out of bounds problem does not occur in the to-be-detected program, and then the corresponding indication may be made according to the system indication. action.
进一步地,如图2所示,在步骤10之前,该检测方法还包括:Further, as shown in FIG. 2, before step 10, the detecting method further includes:
步骤01:根据待检测程序所包含的操作信息申请一内存块。Step 01: Apply for a memory block according to the operation information included in the program to be detected.
待检测程序所包含的操作信息指的是该待检测程序的代码信息,系统可根据代码信息为其分配一合理的内存块。该申请过程可调用内存申请函数进行,系统分配可以使用的内存块时,还会返回该内存块起始地址和内存管理头地址。The operation information included in the program to be detected refers to the code information of the program to be detected, and the system can allocate a reasonable memory block according to the code information. The application process can call the memory application function. When the system allocates a memory block that can be used, it also returns the memory block start address and the memory management header address.
进一步地,如图2所示,该检测方法还包括:Further, as shown in FIG. 2, the detecting method further includes:
步骤02:根据待检测程序所包含的操作信息对内存块进行操作。Step 02: The memory block is operated according to the operation information included in the program to be detected.
按照该待检测程序的代码信息对分得的内存块进行相应的操作,当每次操作完这块内存块后,将调用步骤10、步骤20、步骤30和步骤40所描述的检测过程,以完成对该待检测程序内存越界的检测。Performing corresponding operations on the allocated memory blocks according to the code information of the program to be detected. After each operation of the memory blocks, the detection processes described in steps 10, 20, 30, and 40 are invoked to The detection of the out of bounds of the program to be detected is completed.
进一步地,当检测到该待检测程序发生了内存越界问题,可根据预先设定的处理策略对该段程序进行处理,例如:将该待检测程序记录下来,并挂起执行该待检测程序的进程。Further, when it is detected that the memory out of bounds problem occurs in the to-be-detected program, the segment program may be processed according to a preset processing strategy, for example, the program to be detected is recorded, and the execution of the to-be-detected program is suspended. process.
进一步地,当检测到该待检测程序发生了内存越界问题,亦可自定义对该段程序进行何种处理的处理策略,在根据输入的处理策略对该待检测程序进行相应操作。具体地,为了易用性,可采用成熟的预留命令行的方式,当检测到某一待检测程序发生了内存越界问题,用户可在命令行输入对应的处理策略,使得系统根据该处理策略做出相应处理。 Further, when it is detected that the memory out of bounds problem occurs in the to-be-detected program, the processing strategy for what kind of processing is performed on the segment program may be customized, and the to-be-detected program is correspondingly operated according to the input processing strategy. Specifically, for ease of use, a mature reserved command line may be adopted. When a memory out of bounds problem occurs in a program to be detected, the user may input a corresponding processing policy on the command line, so that the system according to the processing policy Make the appropriate processing.
进一步地,如图1所示,步骤10中获取分配给待检测程序的内存块的起始地址和内存管理头信息的步骤包括:Further, as shown in FIG. 1, the step of obtaining the start address and memory management header information of the memory block allocated to the program to be detected in step 10 includes:
接收待检测程序的内存管理头地址,当为该待检测程序分配内存块时,已记录该内存块的内存管理头地址和内存块起始地址。Receiving a memory management header address of the program to be detected, when a memory block is allocated for the to-be-detected program, the memory management header address and the memory block start address of the memory block are recorded.
根据内存管理头地址查找内存块的起始地址,并读取存储在内存块管理头地址上的内存管理头信息。一般内存管理头地址是内存块起始地址的前一个地址,当读取了内存管理头地址时即可得到内存块的起始地址。当这两个地址不是相邻关系时,亦可直接读取记录在系统中的内存管理头地址和内存块起始地址。在内存管理头地址中记录有内存管理头信息,该内存管理头信息中记录有对应的内存块的大小,以及该内存块是否被释放的释放标记。Find the starting address of the memory block according to the memory management header address, and read the memory management header information stored in the memory block management header address. The general memory management header address is the previous address of the memory block start address. When the memory management header address is read, the start address of the memory block can be obtained. When the two addresses are not adjacent, the memory management head address and the memory block start address recorded in the system can also be directly read. A memory management header information is recorded in the memory management header address, and the size of the corresponding memory block is recorded in the memory management header information, and a release flag of whether the memory block is released.
本发明的内存越界检测方法,通过先检测待检测程序的内存块的合法性,再检测待检测程序是否全部落在内存块的合法范围内,来检测该待检测程序是否发生内存越界,实现了内存越界的快速定位,提高了整个执行该待检测程序的系统的容错性、可靠性和可用性。The memory out-of-bounds detection method of the present invention detects the legality of the memory block of the program to be detected, and then detects whether the program to be detected all falls within the legal range of the memory block, thereby detecting whether the program to be detected has a memory out of bounds, and realizing The fast positioning of the memory out of bounds improves the fault tolerance, reliability and availability of the entire system executing the program to be tested.
如图3所示,依据本发明实施例的另一个方面,还提供了一种内存越界的检测装置,包括:As shown in FIG. 3, according to another aspect of the embodiments of the present invention, a device for detecting an out-of-band memory includes:
第一获取模块101,设置为获取分配给待检测程序的内存块的起始地址和内存管理头信息,内存管理头信息包括:内存块的容量以及释放标记;The first obtaining module 101 is configured to obtain a starting address of the memory block allocated to the program to be detected and memory management header information, where the memory management header information includes: a capacity of the memory block and a release flag;
第一检测模块102,设置为检测释放标记,若释放标记指示内存块已被释放,则判断待检测程序发生内存越界;The first detecting module 102 is configured to detect a release flag, and if the release flag indicates that the memory block has been released, determining that the memory to be detected is out of bounds;
第二获取模块103,设置为当释放标记指示内存块未被释放时,获取待检测程序的第一偏向地址,第一偏向地址为距起始地址最远的偏向地址;The second obtaining module 103 is configured to: when the release flag indicates that the memory block is not released, acquire a first bias address of the to-be-detected program, where the first bias address is a bias address farthest from the start address;
第二检测模块104,设置为根据内存块的容量和起始地址,检测第一偏向地址是否落在内存块的内存范围内;若第一偏向地址未落在内存块的内存范围内,则判断待检测程序发生内存越界。The second detecting module 104 is configured to detect, according to the capacity and the starting address of the memory block, whether the first biasing address falls within the memory range of the memory block; if the first biasing address does not fall within the memory range of the memory block, determining The memory of the program to be tested is out of bounds.
进一步地,该内存越界的检测装置还包括:Further, the detecting device that the memory is out of bounds further includes:
申请模块,设置为根据待检测程序所包含的操作信息申请一内存块。The application module is configured to apply for a memory block according to the operation information included in the program to be detected.
进一步地,该内存越界的检测装置还包括: Further, the detecting device that the memory is out of bounds further includes:
操作模块,设置为根据待检测程序所包含的操作信息对内存块进行操作。The operation module is configured to operate the memory block according to the operation information included in the program to be detected.
进一步地,该内存越界的检测装置还包括:Further, the detecting device that the memory is out of bounds further includes:
处理模块,设置为记录发生内存越界的待检测程序,并挂起执行待检测程序的进程。The processing module is configured to record the program to be detected that the memory is out of bounds, and suspend the process of executing the program to be detected.
进一步地,该内存越界的检测装置还包括:Further, the detecting device that the memory is out of bounds further includes:
扩展模块,设置为获取输入的处理策略,并根据处理策略对待检测程序进行相应操作。The extension module is set to obtain the input processing strategy and perform corresponding operations according to the processing policy.
进一步地,第一获取模块包括:Further, the first obtaining module includes:
接收单元,设置为接收待检测程序的内存管理头地址;a receiving unit, configured to receive a memory management header address of the program to be detected;
获取单元,设置为根据内存管理头地址查找内存块的起始地址,并读取存储在内存块管理头地址上的内存管理头信息。The obtaining unit is configured to search for a starting address of the memory block according to the memory management head address, and read the memory management header information stored in the memory block management header address.
需要说明的是,该装置是与上述内存越界的检测方法对应的装置,上述方法实施例中所有实现方式均适用于该装置的实施例中,也能达到相同的技术效果。It should be noted that the device is a device corresponding to the above-mentioned memory out-of-band detection method. All the implementation manners in the foregoing method embodiments are applicable to the device embodiment, and the same technical effects can be achieved.
以上所述的是本发明的优选实施方式,应当指出对于本技术领域的普通人员来说,在不脱离本发明所述的原理前提下还可以作出若干改进和润饰,这些改进和润饰也在本发明的保护范围内。The above is a preferred embodiment of the present invention, and it should be noted that those skilled in the art can also make several improvements and retouchings without departing from the principles of the present invention. Within the scope of protection of the invention.
工业实用性Industrial applicability
如上所述,本发明实施例提供的一种内存越界的检测方法及装置具有以下有益效果:实现了内存越界的快速定位,提高了整个执行该待检测程序的系统的容错性、可靠性和可用性。 As described above, the method and apparatus for detecting out-of-memory of the memory provided by the embodiment of the present invention have the following beneficial effects: realizing rapid positioning of memory out of bounds, improving fault tolerance, reliability, and availability of the entire system for executing the program to be detected. .

Claims (12)

  1. 一种内存越界的检测方法,包括:A method for detecting an out of bounds memory, including:
    获取分配给待检测程序的内存块的起始地址和内存管理头信息,所述内存管理头信息包括:所述内存块的容量以及释放标记;Obtaining a start address and a memory management header information of a memory block allocated to the program to be detected, where the memory management header information includes: a capacity of the memory block and a release flag;
    检测所述释放标记,若所述释放标记指示所述内存块已被释放,则判断所述待检测程序发生内存越界;Detecting the release flag, if the release flag indicates that the memory block has been released, determining that the memory to be detected is out of bounds;
    若所述释放标记指示所述内存块未被释放,则获取所述待检测程序的第一偏向地址,所述第一偏向地址为距所述起始地址最远的偏向地址;If the release flag indicates that the memory block is not released, acquiring a first bias address of the to-be-detected program, where the first bias address is a bias address that is farthest from the start address;
    根据所述内存块的容量和起始地址,检测所述第一偏向地址是否落在所述内存块的内存范围内;若所述第一偏向地址未落在所述内存块的内存范围内,则判断所述待检测程序发生内存越界。Determining, according to the capacity and the starting address of the memory block, whether the first bias address falls within a memory range of the memory block; if the first bias address does not fall within a memory range of the memory block, Then, it is determined that the program to be detected has a memory out of bounds.
  2. 根据权利要求1所述的内存越界的检测方法,其中,在获取分配给待检测程序的内存块的起始地址和内存管理头信息的步骤之前,还包括:The method for detecting a memory out of bounds according to claim 1, wherein before the step of acquiring a start address and a memory management header information of the memory block allocated to the program to be detected, the method further comprises:
    根据所述待检测程序所包含的操作信息申请一内存块。And applying a memory block according to the operation information included in the to-be-detected program.
  3. 根据权利要求1或2所述的内存越界的检测方法,其中,在获取分配给待检测程序的内存块的起始地址和内存管理头信息的步骤之后,还包括:The method for detecting a memory out of bounds according to claim 1 or 2, wherein after the step of acquiring the start address and the memory management header information of the memory block allocated to the program to be detected, the method further includes:
    根据所述待检测程序所包含的操作信息对所述内存块进行操作。And operating the memory block according to the operation information included in the to-be-detected program.
  4. 根据权利要求1所述的内存越界的检测方法,其中,在判断所述待检测程序发生内存越界的步骤之后,还包括:The method of detecting a memory out of bounds according to claim 1, wherein after the step of determining that the program to be detected has a memory out of bounds, the method further comprises:
    记录发生内存越界的所述待检测程序,并挂起执行所述待检测程序的进程。The program to be detected whose memory is out of bounds is recorded, and the process of executing the program to be detected is suspended.
  5. 根据权利要求1所述的内存越界的检测方法,其中,在判断所述待检测程序发生内存越界的步骤之后,还包括:The method of detecting a memory out of bounds according to claim 1, wherein after the step of determining that the program to be detected has a memory out of bounds, the method further comprises:
    获取输入的处理策略,并根据所述处理策略对所述待检测程序进行相应操作。Obtaining an input processing policy, and performing corresponding operations on the to-be-detected program according to the processing policy.
  6. 根据权利要求1所述的内存越界的检测方法,其中,获取分配给待检测程序的内存块的起始地址和内存管理头信息的步骤包括:The method for detecting a memory out of bounds according to claim 1, wherein the step of acquiring a start address and a memory management header information of the memory block allocated to the program to be detected includes:
    接收所述待检测程序的内存管理头地址; Receiving a memory management header address of the to-be-detected program;
    根据所述内存管理头地址查找所述内存块的起始地址,并读取存储在所述内存块管理头地址上的内存管理头信息。Searching for a starting address of the memory block according to the memory management header address, and reading memory management header information stored at the memory block management header address.
  7. 一种内存越界的检测装置,包括:A memory crossing detection device includes:
    第一获取模块,设置为获取分配给待检测程序的内存块的起始地址和内存管理头信息,所述内存管理头信息包括:所述内存块的容量以及释放标记;a first obtaining module, configured to acquire a starting address and a memory management header information of a memory block allocated to the to-be-detected program, where the memory management header information includes: a capacity of the memory block and a release flag;
    第一检测模块,设置为检测所述释放标记,若所述释放标记指示所述内存块已被释放,则判断所述待检测程序发生内存越界;a first detecting module, configured to detect the release flag, and if the release flag indicates that the memory block has been released, determining that the memory to be detected is out of bounds;
    第二获取模块,设置为当所述释放标记指示所述内存块未被释放时,获取所述待检测程序的第一偏向地址,所述第一偏向地址为距所述起始地址最远的偏向地址;a second obtaining module, configured to acquire a first bias address of the to-be-detected program when the release flag indicates that the memory block is not released, where the first bias address is farthest from the start address Biased address
    第二检测模块,设置为根据所述内存块的容量和起始地址,检测所述第一偏向地址是否落在所述内存块的内存范围内;若所述第一偏向地址未落在所述内存块的内存范围内,则判断所述待检测程序发生内存越界。The second detecting module is configured to detect, according to the capacity and the starting address of the memory block, whether the first biasing address falls within a memory range of the memory block; if the first biasing address does not fall in the Within the memory range of the memory block, it is determined that the memory to be detected is out of bounds.
  8. 根据权利要求7所述的内存越界的检测装置,其中,还包括:The apparatus for detecting an out-of-bounds memory according to claim 7, further comprising:
    申请模块,设置为根据所述待检测程序所包含的操作信息申请一内存块。The application module is configured to apply for a memory block according to the operation information included in the to-be-detected program.
  9. 根据权利要求7或8所述的内存越界的检测装置,其中,还包括:The apparatus for detecting an out-of-bounds memory according to claim 7 or 8, further comprising:
    操作模块,设置为根据所述待检测程序所包含的操作信息对所述内存块进行操作。The operation module is configured to operate the memory block according to the operation information included in the to-be-detected program.
  10. 根据权利要求7所述的内存越界的检测装置,其中,还包括:The apparatus for detecting an out-of-bounds memory according to claim 7, further comprising:
    处理模块,设置为记录发生内存越界的所述待检测程序,并挂起执行所述待检测程序的进程。The processing module is configured to record the to-be-detected program in which the memory is out of bounds, and suspend the process of executing the to-be-detected program.
  11. 根据权利要求7所述的内存越界的检测装置,其中,还包括:The apparatus for detecting an out-of-bounds memory according to claim 7, further comprising:
    扩展模块,设置为获取输入的处理策略,并根据所述处理策略对所述待检测程序进行相应操作。The expansion module is configured to obtain an input processing policy, and perform corresponding operations on the to-be-detected program according to the processing policy.
  12. 根据权利要求7所述的内存越界的检测装置,其中,所述第一获取模块包括:The apparatus for detecting an out-of-bounds memory according to claim 7, wherein the first obtaining module comprises:
    接收单元,设置为接收所述待检测程序的内存管理头地址;a receiving unit, configured to receive a memory management header address of the to-be-detected program;
    获取单元,设置为根据所述内存管理头地址查找所述内存块的起始地址,并读取存储在所述内存块管理头地址上的内存管理头信息。 And an obtaining unit, configured to search for a starting address of the memory block according to the memory management header address, and read memory management header information stored on the memory block management header address.
PCT/CN2015/084147 2015-02-06 2015-07-15 Memory overflow detection method and apparatus WO2016123908A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510063377.6 2015-02-06
CN201510063377.6A CN105988921A (en) 2015-02-06 2015-02-06 Method and device for detecting out of range problem of memory

Publications (1)

Publication Number Publication Date
WO2016123908A1 true WO2016123908A1 (en) 2016-08-11

Family

ID=56563380

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/084147 WO2016123908A1 (en) 2015-02-06 2015-07-15 Memory overflow detection method and apparatus

Country Status (2)

Country Link
CN (1) CN105988921A (en)
WO (1) WO2016123908A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110569037A (en) * 2019-09-06 2019-12-13 北京小米移动软件有限公司 Data writing method and device
CN113377522A (en) * 2020-03-09 2021-09-10 大唐移动通信设备有限公司 Method and device for processing memory blocks in memory pool, electronic equipment and storage medium
CN115373964A (en) * 2022-10-24 2022-11-22 北京智芯微电子科技有限公司 Memory out-of-range detection method, device, equipment and medium

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106919454B (en) * 2017-01-25 2020-02-21 安科讯(福建)科技有限公司 Memory pool problem positioning method and system based on LTE protocol stack
CN110895499A (en) * 2018-09-13 2020-03-20 北京奇虎科技有限公司 Program overflow protection method and device
CN109799992B (en) * 2018-12-05 2022-07-19 交控科技股份有限公司 Method for checking software buffer area range of urban rail transit signal system
CN111338794A (en) * 2020-02-18 2020-06-26 苏州洞察云信息技术有限公司 Memory out-of-range monitoring method and device and storage medium
CN112631821A (en) * 2021-01-28 2021-04-09 长沙景嘉微电子股份有限公司 Memory fault detection positioning method and device, computer equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101110042A (en) * 2006-07-20 2008-01-23 中兴通讯股份有限公司 Method for detecting memory accessing outside
WO2012055188A1 (en) * 2010-10-27 2012-05-03 中兴通讯股份有限公司 Terminal and method for checking data in internal memory of terminal
CN103745755A (en) * 2014-01-06 2014-04-23 中国科学院软件研究所 Space memory error detection method with high efficiency and high availability

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101561775B (en) * 2009-05-12 2010-09-15 华为技术有限公司 Method and device for monitoring memory
JP2012150535A (en) * 2011-01-17 2012-08-09 Fujitsu Ltd Program verification method and program verification program

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101110042A (en) * 2006-07-20 2008-01-23 中兴通讯股份有限公司 Method for detecting memory accessing outside
WO2012055188A1 (en) * 2010-10-27 2012-05-03 中兴通讯股份有限公司 Terminal and method for checking data in internal memory of terminal
CN103745755A (en) * 2014-01-06 2014-04-23 中国科学院软件研究所 Space memory error detection method with high efficiency and high availability

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110569037A (en) * 2019-09-06 2019-12-13 北京小米移动软件有限公司 Data writing method and device
CN110569037B (en) * 2019-09-06 2023-03-31 北京小米移动软件有限公司 Data writing method and device
CN113377522A (en) * 2020-03-09 2021-09-10 大唐移动通信设备有限公司 Method and device for processing memory blocks in memory pool, electronic equipment and storage medium
CN115373964A (en) * 2022-10-24 2022-11-22 北京智芯微电子科技有限公司 Memory out-of-range detection method, device, equipment and medium
CN115373964B (en) * 2022-10-24 2023-01-20 北京智芯微电子科技有限公司 Memory out-of-range detection method, device, equipment and medium

Also Published As

Publication number Publication date
CN105988921A (en) 2016-10-05

Similar Documents

Publication Publication Date Title
WO2016123908A1 (en) Memory overflow detection method and apparatus
US7000225B2 (en) Method for inserting global breakpoints
US10121004B2 (en) Apparatus and method for monitoring virtual machine based on hypervisor
TWI470420B (en) Dubugging method and computer system using the smae
US10817211B2 (en) Method for completing a secure erase operation
TW200419448A (en) Privileged-based qualification of branch trace store data
US9189426B2 (en) Protected access to virtual memory
JP5832954B2 (en) Tag assignment device and tag assignment method
CN108898012B (en) Method and apparatus for detecting illegal program
CN110727597A (en) Method for completing use case based on log troubleshooting invalid codes
WO2017148271A1 (en) Linux system reset processing method and device, and computer storage medium
US20240095174A1 (en) Method for detecting error of operating system kernel memory in real time
CN104461880A (en) Method for automatically detecting heap corruption in embedded system
US9778969B2 (en) Automatic memory leak detection
JP2016537730A (en) Detecting read access to unallocated or uninitialized memory
CN107766385B (en) Method and equipment for converting file format of virtual disk
US20090271584A1 (en) Controller of storage device, storage device, and control method of storage device
JP2009217617A (en) Method and device for identifying memory leak place
EP2960798B1 (en) Automatic memory leak detection
WO2017076034A1 (en) Method and device for formatting memory of mobile terminal
CN111338794A (en) Memory out-of-range monitoring method and device and storage medium
CN103164290A (en) Management method and management device of application memory
CN107707856B (en) Method and device for recording multimedia program
CN105808445A (en) Embedded flash memory and sector processing method and device thereof
JP2006018705A (en) Memory access trace system and memory access trace method

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15880863

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15880863

Country of ref document: EP

Kind code of ref document: A1