计算机工程与应用 ›› 2022, Vol. 58 ›› Issue (19): 76-87.DOI: 10.3778/j.issn.1002-8331.2202-0254

• 理论与研发 • 上一篇    下一篇

跟踪机制引导的C程序内存错误自动修复

董玉坤,位欣欣,孙玉雪,唐道龙   

  1. 中国石油大学(华东) 计算机科学与技术学院,山东 青岛 266580
  • 出版日期:2022-10-01 发布日期:2022-10-01

Automatic Repair of C Program Memory Error Guided by Tracking Mechanism

DONG Yukun, WEI Xinxin, SUN Yuxue, TANG Daolong   

  1. School of Computer Science and Technology, China University of Petroleum(East China), Qingdao, Shandong 266580, China
  • Online:2022-10-01 Published:2022-10-01

摘要: C语言执行效率高,使用范围广泛,然而存在的安全问题也日益突出。内存错误是C程序中常见的缺陷,严重时将导致系统崩溃。传统的人工修复内存错误耗费大量人力物力,并可能在修复过程中引入新的错误。针对这个问题,提出了一种基于跟踪机制的程序自动修复方法。构建包含程序文件中变量作用分布的作用域树;提出基于全局指针的跟踪机制,通过插入全局指针跟踪发生错误的分配内存在程序中的状态;基于全局指针自动生成补丁,利用作用域树定位缺陷修复位置从而来安全地修复内存错误。基于上述过程,实现了原型工具DTSFix,并在开源程序中对其进行了评估。实验结果表明,DTSFix能够有效检测并修复程序中的真实缺陷而且不产生副作用。

关键词: 跟踪机制, 程序自动修复, 内存错误, 作用域树

Abstract: C is a highly efficient and widely used language, but its widespread use has been accompanied by growing security issues. The memory error is a common error in C programs, which will cause the system to collapse in severe cases. Manually fixing memory error requires considerable efforts, and potentially introduces new errors in the repair process. To address this problem, an automatic program repair method based on tracking mechanism is proposed. Firstly, it constructs the scope-tree containing the distribution of variables in the program file. Then, a global pointer-based tracking mechanism is proposed to track the state of allocated memory with errors in the program. Finally, a patch is automatically generated based on a global pointer, and a scope-tree is used to locate where the defect is fixed so that the memory error can be safely repaired. Based on the above process, the prototype tool DTSFix has implemented, in addition evaluated it with open-source programs. The experimental results show that DTSFix can effectively detect and repair the real defects in open-source programs without side effects.

Key words: tracing mechanism, automatic program repair, memory errors, scope tree