CN104133733A - Memory error detection method - Google Patents
Memory error detection method Download PDFInfo
- Publication number
- CN104133733A CN104133733A CN201410366790.5A CN201410366790A CN104133733A CN 104133733 A CN104133733 A CN 104133733A CN 201410366790 A CN201410366790 A CN 201410366790A CN 104133733 A CN104133733 A CN 104133733A
- Authority
- CN
- China
- Prior art keywords
- application program
- memory
- described application
- record
- memory error
- 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.)
- Granted
Links
Landscapes
- Debugging And Monitoring (AREA)
- Storage Device Security (AREA)
- Techniques For Improving Reliability Of Storages (AREA)
Abstract
The invention discloses a memory error detection method which is applied for memory error detection of computer application programs. The method comprises the steps that static analysis is carried out on an application program, and a memory error feature model is built for the application program; the application program runs, and a legal address base of the application program is created and dynamically maintained by means of the memory error feature model; a memory address to which the application program will have access is computed and is matched with a record in the legal address base every time before the application program has access to the memory address, and it is shown that the memory errors exist on the application program if matching cannot be achieved or the record created by a memory distribution function still exists in the legal address base before program running is finished. The memory error detection method can effectively detect four common kinds of memory errors such as cross-border access, pointer illegal access, memory error release and memory leak in the computer application programs.
Description
Technical field
The invention belongs to security of computer software and reliability and ensure field, relate in particular to the detecting memory errors method of computer applied algorithm.
Background technology
In C/C++ language owing to can directly calculator memory address space being operated, though greatly facilitated programmer, but in specific operation process, because programmer's carelessness or technical merit own are limited, in program, always inevitably occur comprising that Array Bound, wild pointer access, null pointer are quoted, internal memory discharges the EMS memory error such as mistake and RAM leakage.These EMS memory error are generally difficult to just be found in debug process, are also quite time-consuming even if find out, and particularly occur in the program of call relation more complicated between the huge or module of size of code.EMS memory error, except causing program run-time error and system crash, also may cause the problems such as buffer overflow, thereby affect security of system.So, before the comparatively harsh system of reliability and security requirement is disposed, be necessary very much computer applied algorithm to carry out detecting memory errors.And existing detecting memory errors technology all can only detect one or more mistakes of above-mentioned EMS memory error substantially, the root of having no idea to occur from EMS memory error, above-mentioned all EMS memory error are detected.
Summary of the invention
Technology of the present invention is dealt with problems: overcome the deficiencies in the prior art, provide a kind of and can detect that computer applied algorithm comprises that out-of-bounds access, pointer are illegally quoted, EMS memory error discharges and the method for the four large common EMS memory error of class such as RAM leakage from root, ensured the safety and reliability of computer software.
Core concept of the present invention is before application program access memory address space, and the memory address space that just it is about to access is verified.If checking is not passed through, the EMS memory error problem that exists is described; Otherwise the EMS memory error problem that do not exist is described, program continues operation.So repeatedly, until program end of run or moved by abnormal end.
Detection method provided by the invention comprises the following steps: as shown in Figure 1:
Step 101, application programs is carried out static analysis, completes the EMS memory error feature modeling to described application program.
Wherein, the process of the EMS memory error feature modeling to described application program is that the statement of EMS memory error and positional information identification and the process recording likely appear in described application program in identification, this EMS memory error characteristic model comprise the fatal error nodes such as array in described application program, pointer, dangerous string operation function, memory allocation and release function statement, quote or the positional information at call statement place and quoting or recalls information.
Step 102, moves described application program, utilizes EMS memory error characteristic model, creates and overall legal address storehouse of Dynamic Maintenance.
In the process of the described application program of operation, need to complete the establishment in the legal address storehouse of described application program according to the data that obtain in EMS memory error characteristic model and step (101).
Described legal address library storage the record of described application program at current instant effective all memory address spaces of when operation, each in described legal address storehouse records an object in corresponding described application program.Described object refers to the grammer individuality that described application program can individualism in internal memory, i.e. described application program variable or a function.
Record in described legal address storehouse can, along with the continuous operation of described application program, can be constantly updated by the application of assignment, function call and internal memory and releasing operation because of statement, the variable of variable.Wherein, variable declarations or while newly applying for successful internal memory need to create the record of uniting as one in legal address storehouse; Variable during by assignment, need to be revised the legal address scope of associated record in legal address storehouse; When variable or function depart from action scope or discharge successful internal memory, need to delete associated record in legal address storehouse.
Step 103, in the operation of described application program complete or moved by abnormal end before, before the each access memory of described application program, all first calculate the address realm that is about to access, and match with the record in legal address storehouse; If cannot match, will there is EMS memory error in explanation, record relevant error information.
Wherein, not to comprise and involved relation if initiate grammar object local scope in associated record in described legal address storehouse of access in the address realm calculating and described application program, explanation is worked as time access and will be occurred EMS memory error.Now only need judge EMS memory error type and other relevant informations that may occur according to type, the action type of the actual relation of inclusion of aforementioned two address realms and described grammar object.
Step 104, moves complete or in inspection legal address storehouse, whether is had the record being created by memory allocation function afterwards by abnormal end operation in described application program; If exist, illustrate RAM leakage mistake has occurred, record relevant error information.
The present invention compared with prior art advantage is: detecting memory errors method provided by the invention is owing to being, root, computer applied algorithm is carried out to detecting memory errors, so can ensure the validity of the method super current all detecting memory errors methods far away, and the quantity of the EMS memory error detecting can contain all common EMS memory error.
Brief description of the drawings
Fig. 1 is the process flow diagram of detecting memory errors method of the present invention;
Fig. 2 is EMS memory error feature modeling process flow diagram in the embodiment of the present invention;
Fig. 3 is the Dynamic Maintenance process flow diagram in legal address storehouse in the embodiment of the present invention;
Fig. 4 is legal address storehouse schematic diagram in the embodiment of the present invention.
Embodiment
Below in conjunction with embodiment of the present invention accompanying drawing, the technical scheme in the embodiment of the present invention is removed, intactly described, obvious described embodiment is only some embodiments of the present application, instead of whole embodiment.
If Fig. 2 is EMS memory error feature modeling process flow diagram in the embodiment of the present invention, described method step is as follows:
Step 201, carries out lexical analysis to application program to be measured, obtains the lexical unit sequence of described application program.
Step 202, carries out grammatical analysis to described application program, generates abstract syntax tree.
Wherein, step 201 and 202 can complete by GNU GCC compiler or the lexical analysis of increasing income, grammatical analysis builder tool LEX/YACC.
Step 203, analyzes abstract syntax tree, identifies EMS memory error characteristic node in described application program, records its relevant information.
Described EMS memory error characteristic node refers to all statements relevant to internal memory operation.In C/C++ language, the one of internal memory operation correlative classifies as: apply for internal memory, releasing memory, write internal memory and rdma read.All internal memory operation correlative place filename, line number, action scopes all need to be recorded, in addition, different operating statement also needs the information of record to comprise: in the time of application internal memory, also need to record the associated pointer name of this application operation, the memory headroom type of application, the memory size expression formula of applying for handling function and application; When releasing memory, also need to record the releasing operation function and associated pointer name of this releasing operation; While writing internal memory, also need to record this destination object name of writing internal memory operation, source object name and write big or small expression formula; When rdma read, also need to record this rdma read operation source object name, read in big or small expression formula.
Step 204, by the above-mentioned write memory error characteristic model essence data files that records.
Wherein, to the reading of described EMS memory error characteristic model essence data files, need to be stored as XML form by this file for ease of subsequent detection process.
If Fig. 3 is the Dynamic Maintenance process flow diagram in legal address storehouse in the embodiment of the present invention, specifically comprise the following steps:
Step 301, reads EMS memory error characteristic model basic data, pitching pile before each EMS memory error characteristic node.Wherein, in the pile function of insertion, comprise: unique internal memory operation identification number, calculate by the method for the method in reference address space, retrieval EMS memory error characteristic model, record the method for relevant error information.
Step 302, moves described application program, creates the data capsule for storing legal address storehouse.Due to the renewal of recording in legal address storehouse and inquiry very frequent, therefore require the search performance of storage container in legal address storehouse good especially, consider that Hash table can reduce the storage of data and the time of searching consumption greatly, can consider to complete with Hash table the storage in legal address storehouse.
If Fig. 4 is legal address storehouse schematic diagram in the embodiment of the present invention.In this legal address storehouse, comprise field: cryptographic hash, object name, object type, legal address scope, step value, object of the same name, object type of the same name, action scope, filename and line number.Wherein, step value refers to the byte number that pointer moves at every turn; Object of the same name refers to the variable that memory address is identical.
Step 303, reads the corresponding statement of each EMS memory error characteristic node, removes to retrieve EMS memory error characteristic model using the line number of this statement as parameter, determines the type of this statement corresponding node.Described node type comprises: variable statement node, variable are departed from action scope node, internal memory application node and internal memory by Evaluation node, variable or function and discharge node.
Step 304, according to the type of node, has just upgraded the record in legal address storehouse.
Wherein, discharge successfully if node type is releasing memory and internal memory, delete corresponding record in legal address storehouse;
Depart from action scope if node type is variable or function, delete corresponding record in legal address storehouse;
If node type is variable declarations, in legal address storehouse, create a record;
If node type be variable by assignment, upgrade the legal address scope of corresponding record in legal address storehouse; If this variable exists variable of the same name, need synchronously to upgrade the legal address scope of this variable of the same name;
If node type is internal memory application and internal memory application success, in legal address storehouse, add a record.
Detecting memory errors of the present invention carries out based on legal address storehouse, whether the memory address space that application program all needs calculated in advance to be about to access before to the access of memory address space mates with the memory address space in corresponding record in legal address storehouse, if unmatch or still have record in legal address storehouse after application program end of run or application program be by abnormal end operation, the generation of EMS memory error has all been described.
Should be noted that; the foregoing is only better case study on implementation of the present invention; can not therefore think the restriction to scope of patent protection of the present invention, not departing from all equivalent improvements and modifications of core concept of the present invention, all belong to protection scope of the present invention.
Claims (5)
1. a detecting memory errors method, is applied to the real-time performance testing to embedded system, it is characterized in that: said method comprising the steps of:
(1) application programs is carried out static analysis, completes the EMS memory error feature modeling to described application program;
(2) move described application program, utilize described EMS memory error characteristic model, create and Dynamic Maintenance described in the legal address storehouse of application program;
(3) complete in the operation of described application program or moved by abnormal end before, before the each access memory of described application program, all first calculate the address realm that is about to access, and match with the record in legal address storehouse; If cannot match, will there is EMS memory error in explanation, record relevant error information;
(4) move complete or in inspection legal address storehouse, whether had the record being created by memory allocation function afterwards by abnormal end operation in described application program; If exist, illustrate RAM leakage mistake has occurred, record relevant error information.
2. method according to claim 1, it is characterized in that: in described step (1), the EMS memory error feature modeling of described application program is referred to and will in described application program, likely occur that the statement of EMS memory error and positional information identify, and build EMS memory error characteristic model.Described EMS memory error characteristic model comprise the fatal error nodes such as array in described application program, pointer, dangerous string operation function, memory allocation and release function statement, quote or the positional information at call statement place and quoting or recalls information.
3. method according to claim 1, it is characterized in that: in described step (2), described legal address storehouse refers to the warehouse that has comprised described application program current instant effective all memory address spaces in the time of operation, every object recording in corresponding described application program in warehouse, described object refers to the grammer individuality that described application program can individualism in internal memory, i.e. described application program variable or a function.
4. method according to claim 1, it is characterized in that: in described step (2), the rule of applying journey described in Dynamic Maintenance is: when described application program has just brought into operation, just, according to EMS memory error characteristic model initialization legal address storehouse, create the data capsule for legal address storehouse record; Along with the continuous operation of described application program, the statement of variable, variable are all needed the record in continuous increase, amendment, deletion legal address storehouse by the application of assignment, function call and internal memory and release; Wherein, variable declarations or while newly applying for successful internal memory need to create a new record in legal address storehouse; Variable during by assignment, need to be revised the legal address scope of associated record in legal address storehouse; When variable or function depart from action scope or discharge successful internal memory, need to delete associated record in legal address storehouse.
5. method according to claim 1, it is characterized in that: in described step (3), before the each access memory of described application program, all first calculate the address realm that is about to access, if initiating grammar object local scope in associated record in described legal address storehouse of access in the address realm calculating and described application program is not to comprise and involved relation, explanation is worked as time access and will be occurred EMS memory error, now only need be according to the actual relation of inclusion of aforementioned two address realms and the type of described grammar object, action type judges EMS memory error type and other relevant informations that may occur.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410366790.5A CN104133733B (en) | 2014-07-29 | 2014-07-29 | A kind of detecting memory errors method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410366790.5A CN104133733B (en) | 2014-07-29 | 2014-07-29 | A kind of detecting memory errors method |
Publications (2)
Publication Number | Publication Date |
---|---|
CN104133733A true CN104133733A (en) | 2014-11-05 |
CN104133733B CN104133733B (en) | 2017-03-29 |
Family
ID=51806418
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410366790.5A Active CN104133733B (en) | 2014-07-29 | 2014-07-29 | A kind of detecting memory errors method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104133733B (en) |
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104636256A (en) * | 2015-02-17 | 2015-05-20 | 中国农业银行股份有限公司 | Memory access abnormity detecting method and memory access abnormity detecting device |
CN105354104A (en) * | 2015-10-22 | 2016-02-24 | 上海华为技术有限公司 | Illegal address positioning apparatus and method |
CN105389272A (en) * | 2015-12-03 | 2016-03-09 | 上海高性能集成电路设计中心 | IO device time-division and domain-division management and control apparatus and method in security computer system |
CN106055478A (en) * | 2016-05-31 | 2016-10-26 | 腾讯科技(深圳)有限公司 | Method and device for detecting memory leak |
CN106485138A (en) * | 2016-09-08 | 2017-03-08 | 大唐微电子技术有限公司 | A kind of Java card anti-attack method and device |
CN106502926A (en) * | 2016-09-26 | 2017-03-15 | 华为技术有限公司 | A kind of internal memory monitoring method, internal storage access controller and SoC systems |
CN111611158A (en) * | 2020-05-08 | 2020-09-01 | 中国原子能科学研究院 | Application performance analysis system and method |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5644709A (en) * | 1994-04-21 | 1997-07-01 | Wisconsin Alumni Research Foundation | Method for detecting computer memory access errors |
CN1188933A (en) * | 1998-02-06 | 1998-07-29 | 深圳市华为技术有限公司 | Recognition method for internal stored operation error in programming |
US6105033A (en) * | 1997-12-29 | 2000-08-15 | Bull Hn Information Systems Inc. | Method and apparatus for detecting and removing obsolete cache entries for enhancing cache system operation |
CN101571828A (en) * | 2009-06-11 | 2009-11-04 | 北京航空航天大学 | Method for detecting code security hole based on constraint analysis and model checking |
CN103745755A (en) * | 2014-01-06 | 2014-04-23 | 中国科学院软件研究所 | Space memory error detection method with high efficiency and high availability |
-
2014
- 2014-07-29 CN CN201410366790.5A patent/CN104133733B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5644709A (en) * | 1994-04-21 | 1997-07-01 | Wisconsin Alumni Research Foundation | Method for detecting computer memory access errors |
US6105033A (en) * | 1997-12-29 | 2000-08-15 | Bull Hn Information Systems Inc. | Method and apparatus for detecting and removing obsolete cache entries for enhancing cache system operation |
CN1188933A (en) * | 1998-02-06 | 1998-07-29 | 深圳市华为技术有限公司 | Recognition method for internal stored operation error in programming |
CN101571828A (en) * | 2009-06-11 | 2009-11-04 | 北京航空航天大学 | Method for detecting code security hole based on constraint analysis and model checking |
CN103745755A (en) * | 2014-01-06 | 2014-04-23 | 中国科学院软件研究所 | Space memory error detection method with high efficiency and high availability |
Non-Patent Citations (1)
Title |
---|
高海昌等: ""Linux平台下基于源代码插装的动态内存检测"", 《小型微型计算机系统》 * |
Cited By (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104636256A (en) * | 2015-02-17 | 2015-05-20 | 中国农业银行股份有限公司 | Memory access abnormity detecting method and memory access abnormity detecting device |
CN104636256B (en) * | 2015-02-17 | 2017-10-24 | 中国农业银行股份有限公司 | A kind of abnormal detection method and device of internal storage access |
CN105354104A (en) * | 2015-10-22 | 2016-02-24 | 上海华为技术有限公司 | Illegal address positioning apparatus and method |
CN105354104B (en) * | 2015-10-22 | 2019-03-26 | 上海华为技术有限公司 | A kind of device and method positioning illegal address |
CN105389272A (en) * | 2015-12-03 | 2016-03-09 | 上海高性能集成电路设计中心 | IO device time-division and domain-division management and control apparatus and method in security computer system |
CN105389272B (en) * | 2015-12-03 | 2018-06-05 | 上海高性能集成电路设计中心 | I/O device timesharing divides domain control device and method in a kind of trusted computer system |
CN106055478A (en) * | 2016-05-31 | 2016-10-26 | 腾讯科技(深圳)有限公司 | Method and device for detecting memory leak |
CN106485138A (en) * | 2016-09-08 | 2017-03-08 | 大唐微电子技术有限公司 | A kind of Java card anti-attack method and device |
CN106502926A (en) * | 2016-09-26 | 2017-03-15 | 华为技术有限公司 | A kind of internal memory monitoring method, internal storage access controller and SoC systems |
CN106502926B (en) * | 2016-09-26 | 2019-11-19 | 华为技术有限公司 | A kind of internal memory monitoring method, internal storage access controller and SoC system |
CN111611158A (en) * | 2020-05-08 | 2020-09-01 | 中国原子能科学研究院 | Application performance analysis system and method |
Also Published As
Publication number | Publication date |
---|---|
CN104133733B (en) | 2017-03-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN104133733A (en) | Memory error detection method | |
US11157640B2 (en) | Protecting sensitive data in software products and in generating core dumps | |
CN106940654B (en) | Automatic detection and positioning method for memory error in source code | |
CN103440201A (en) | Dynamic taint analysis device and application thereof to document format reverse analysis | |
CN105184166A (en) | Kernel-based Android application real-time behavior analysis method and system | |
CN104156314A (en) | Code reuse method applied to test system | |
CN103186468B (en) | A kind of method and apparatus of verifying software upgrading accuracy | |
US9021455B2 (en) | Packed data objects | |
CN104969181B (en) | Repair system, method and the storage equipment that driver variable for damage records | |
CN102981882B (en) | Analytic method and device | |
CN103019787A (en) | Function call relation determining method, hotfix updating method and hotfix updating device | |
CN104133699A (en) | Equipment system software upgrading method and system | |
CN112925524A (en) | Method and device for detecting unsafe direct memory access in driver | |
CN115617687A (en) | Program instrumentation method, apparatus, device and storage medium | |
CN104461880A (en) | Method for automatically detecting heap corruption in embedded system | |
US9588884B2 (en) | Systems and methods for in-place reorganization of device storage | |
CN103235757B (en) | Several apparatus and method that input domain tested object is tested are made based on robotization | |
CN113987507A (en) | Heap memory vulnerability detection method and device, storage medium and electronic equipment | |
CN111475150B (en) | Cross-language binding method, device, equipment and storage medium | |
CN100470683C (en) | Method for implementing dynamic storage error static detecting of embedded system | |
WO2017076244A1 (en) | Method, device and related system for dynamically repairing application | |
CN117055894A (en) | Source code statement instrumentation method for memory error detection | |
CN114282227B (en) | Safety analysis and detection method for intelligent contract of Fabric block chain system | |
CN112966258B (en) | Control flow integrity protection method, system and device and readable storage medium | |
CN114153451A (en) | Method for analyzing memory security in C code by using data flow analysis algorithm |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |