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 条
  • [21] Techniques for Memory-Efficient Model Checking of C and C plus plus Code
    Rockai, Petr
    Still, Vladimir
    Barnat, Jiri
    [J]. SOFTWARE ENGINEERING AND FORMAL METHODS, 2015, 9276 : 268 - 282
  • [22] A Context-Sensitive Memory Model for Verification of C/C plus plus Programs
    Gurfinkel, Arie
    Navas, Jorge A.
    [J]. STATIC ANALYSIS (SAS 2017), 2017, 10422 : 148 - 168
  • [23] Detection of Memory Leaks in C/C plus plus Code via Machine Learning
    Andrzejak, Artur
    Eichler, Felix
    Ghanavati, Mohammadreza
    [J]. 2017 IEEE 28TH INTERNATIONAL SYMPOSIUM ON SOFTWARE RELIABILITY ENGINEERING WORKSHOPS (ISSREW 2017), 2017, : 252 - 258
  • [24] CHERI: Hardware-Enabled C/C plus plus Memory Protection at Scale
    Watson, Robert N. M.
    Chisnall, David
    Clarke, Jessica
    Davis, Brooks
    Filardo, Nathaniel Wesley
    Laurie, Ben
    Moore, Simon W.
    Neumann, Peter G.
    Richardson, Alexander
    Sewell, Peter
    Witaszczyk, Konrad
    Woodruff, Jonathan
    [J]. IEEE SECURITY & PRIVACY, 2024, 22 (04) : 50 - 61
  • [25] Detecting C plus plus Compiler Front-End Bugs via Grammar Mutation and Differential Testing
    Tu, Haoxin
    Jiang, He
    Zhou, Zhide
    Tang, Yixuan
    Ren, Zhilei
    Qiao, Lei
    Jiang, Lingxiao
    [J]. IEEE TRANSACTIONS ON RELIABILITY, 2023, 72 (01) : 343 - 357
  • [26] Influence of bupropion and calcium channel antagonists on the nicotine-induced memory-related response of mice in the elevated plus maze
    Biała G.
    Kruk M.
    [J]. Pharmacological Reports, 2009, 61 (2) : 236 - 244
  • [27] Learning-Based Memory Allocation for C plus plus Server Workloads
    Lea, Doug
    [J]. COMMUNICATIONS OF THE ACM, 2024, 67 (04) : 82 - 82
  • [28] Learning-based Memory Allocation for C plus plus Server Workloads
    Maas, Martin
    Andersen, David G.
    Isard, Michael
    Javanmard, Mohammad Mahdi
    McKinley, Kathryn S.
    Raffel, Colin
    [J]. TWENTY-FIFTH INTERNATIONAL CONFERENCE ON ARCHITECTURAL SUPPORT FOR PROGRAMMING LANGUAGES AND OPERATING SYSTEMS (ASPLOS XXV), 2020, : 541 - 556
  • [29] Pattern-based Synthesis of Synchronization for the C plus plus Memory Model
    Meshman, Yuri
    Rinetzky, Noam
    Yahav, Eran
    [J]. PROCEEDINGS OF THE 15TH CONFERENCE ON FORMAL METHODS IN COMPUTER-AIDED DESIGN (FMCAD 2015), 2015, : 120 - 127
  • [30] Influence of bupropion and calcium channel antagonists on the nicotine-induced memory-related response of mice in the elevated plus maze
    Biala, Grazyna
    Kruk, Marta
    [J]. PHARMACOLOGICAL REPORTS, 2009, 61 (02) : 236 - 244