Detecting Memory-Related Bugs by Tracking Heap Memory Management of C plus plus Smart Pointers

被引:5
|
作者
Ma, Xutong [1 ,3 ]
Yan, Jiwei [2 ,3 ]
Wang, Wei [1 ,3 ]
Yan, Jun [1 ,2 ,3 ]
Zhang, Jian [1 ,3 ]
Qiu, Zongyan [4 ]
机构
[1] Chinese Acad Sci, State Key Lab Comp Sci, Inst Software, Beijing, Peoples R China
[2] Chinese Acad Sci, Technol Ctr Software Engn, Inst Software, Beijing, Peoples R China
[3] Univ Chinese Acad Sci, Beijing, Peoples R China
[4] Peking Univ, Sch Math Sci, Beijing, Peoples R China
关键词
C plus plus Smart Pointer; Memory Errors;
D O I
10.1109/ASE51524.2021.9678836
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
The smart pointer mechanism, which is improved in the continuous versions of the C++ standards over the last decade, is designed to prevent memory-leak bugs by automatically deallocating the managed memory blocks. However, not all kinds of memory errors can be immunized by adopting this mechanism. For example, dereferencing a null smart pointer will lead to a software failure. Due to the lack of specialized support for smart pointers, the off-the-shelf C++ static analyzers cannot effectively reveal these bugs. In this paper, we propose a static approach to detecting memory-related bugs by tracking the heap memory management of smart pointers. The behaviors of smart pointers are modeled during their lifetime to trace the state transitions of managed memory blocks. And the specially designed checkers are used to check the state changes according to five collected bug patterns. To evaluate the effectiveness of our approach, we implement it on the top of the Clang Static Analyzer. A set of handmade code snippets, as well as nine popular open-source C++ projects, are used to compare our tool against four other analyzers. The results show that our approach can successfully discover nearly all the built-in bugs. And 442 out of 648 reports generated from the open-source projects are true positives after manual reviewing, where the bugs of dereferencing null smart pointers are most frequently reported. To further confirm our reports, we design patches for Aria2, Restbed, MySQL and LLVM, in which seven pull requests covering 76 bug reports have been merged by the developers up to now. The results indicate that pointers should always be carefully used even after migrated to smart pointers and static analysis upon specialized models can effectively detect such bugs.
引用
收藏
页码:880 / 891
页数:12
相关论文
共 50 条
  • [1] MESH: A Memory-Efficient Safe Heap for C/C plus
    Vintila, Emanuel Q.
    Zieris, Philipp
    Horsch, Julian
    [J]. ARES 2021: 16TH INTERNATIONAL CONFERENCE ON AVAILABILITY, RELIABILITY AND SECURITY, 2021,
  • [2] Detecting Exception Handling Bugs in C plus plus Programs
    Zhang, Hao
    Luo, Ji
    Hu, Mengze
    Yan, Jun
    Zhang, Jian
    Qiu, Zongyan
    [J]. 2023 IEEE/ACM 45TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING, ICSE, 2023, : 1084 - 1095
  • [3] MESH: Compacting Memory Management for C/C plus plus Applications
    Powers, Bobby
    Tench, David
    Berger, Emery D.
    McGregor, Andrew
    [J]. PROCEEDINGS OF THE 40TH ACM SIGPLAN CONFERENCE ON PROGRAMMING LANGUAGE DESIGN AND IMPLEMENTATION (PLDI '19), 2019, : 333 - 346
  • [4] AccMon: Automatically detecting memory-related bugs via program counter-based invariants
    Zhou, P
    Liu, W
    Fei, L
    Lu, S
    Qin, F
    Zhou, YY
    Midkiff, S
    Torrellas, J
    [J]. MICRO-37 2004: 37TH ANNUAL INTERNATIONAL SYMPOSIUM ON MICROARCHITECTURE, PROCEEDINGS, 2004, : 269 - 280
  • [5] HWASanIO: Detecting C/C plus plus Intra-object Overflows with Memory Shading
    Hohentanner, Konrad
    Kasten, Florian
    Auer, Lukas
    [J]. PROCEEDINGS OF THE 12TH ACM SIGPLAN INTERNATIONAL WORKSHOP ON THE STATE OF THE ART IN PROGRAM ANALYSIS, SOAP 2023, 2023, : 27 - 33
  • [6] On Monitoring C/C plus plus Transactional Memory Programs
    Fiedor, Jan
    Letko, Zdenek
    Lourenco, Joao
    Vojnar, Tomas
    [J]. MATHEMATICAL AND ENGINEERING METHODS IN COMPUTER SCIENCE, MEMICS 2014, 2014, 8934 : 73 - 87
  • [7] Memory-related effects of cholinergic receptor ligands in mice as measured by the elevated plus maze test
    Marta Kruk
    Kinga Tendera
    Grażyna Biała
    [J]. Pharmacological Reports, 2011, 63 (6) : 1372 - 1382
  • [8] Foundations of the C plus plus Concurrency Memory Model
    Boehm, Hans-J.
    Adve, Sarita V.
    [J]. PLDI'08: PROCEEDINGS OF THE 2008 SIGPLAN CONFERENCE ON PROGRAMMING LANGUAGE DESIGN & IMPLEMENTATION, 2008, : 68 - 78
  • [9] Memory-related effects of cholinergic receptor ligands in mice as measured by the elevated plus maze test
    Kruk, Marta
    Tendera, Kinga
    Biala, Grazyna
    [J]. PHARMACOLOGICAL REPORTS, 2011, 63 (06) : 1372 - 1382
  • [10] Enhanced Memory Corruption Detection in C/C plus plus Programs
    Lin, Ching-Yi
    Yang, Wuu
    [J]. PROCEEDINGS OF THE 52ND INTERNATIONAL CONFERENCE ON PARALLEL PROCESSING WORKSHOPS PROCEEDINGS, ICPP-W 2023, 2023, : 71 - 78