[论文解读] Testing Database Engines via Pivoted Query Synthesis
本文提出了一种新颖且通用的方法——SQLancer,通过合成旨在检索特定且随机选择的“基准行”的查询,来检测数据库管理系统(DBMS)中的逻辑错误。通过确保查询必须将该基准行包含在结果集中,该方法充当一种包含性预言机;若DBMS未能返回基准行,则触发逻辑错误。该方法在SQLite、MySQL和PostgreSQL中发现了123个错误,其中99个已修复或经验证,证明了其高效性和广泛适用性。
Relational databases are used ubiquitously. They are managed by database management systems (DBMS), which allow inserting, modifying, and querying data using a domain-specific language called Structured Query Language (SQL). Popular DBMS have been extensively tested by fuzzers, which have been successful in finding crash bugs. However, approaches to finding logic bugs, such as when a DBMS computes an incorrect result set, have remained mostly untackled. Differential testing is an effective technique to test systems that support a common language by comparing the outputs of these systems. However, this technique is ineffective for DBMS, because each DBMS typically supports its own SQL dialect. To this end, we devised a novel and general approach that we have termed Pivoted Query Synthesis. The core idea of this approach is to automatically generate queries for which we ensure that they fetch a specific, randomly selected row, called the pivot row. If the DBMS fails to fetch the pivot row, the likely cause is a bug in the DBMS. We tested our approach on three widely-used and mature DBMS, namely SQLite, MySQL, and PostgreSQL. In total, we reported 123 bugs in these DBMS, 99 of which have been fixed or verified, demonstrating that the approach is highly effective and general. We expect that the wide applicability and simplicity of our approach will enable the improvement of robustness of many DBMS.
研究动机与目标
- 为解决DBMS中不引发崩溃但返回错误结果的逻辑错误检测挑战。
- 克服差异测试的局限性,后者在DBMS支持不同SQL方言和语义时会失效。
- 设计一种轻量级、通用的测试预言机,确保特定行被包含在查询结果中。
- 实现对成熟、广泛使用的DBMS中先前未被发现的逻辑错误的自动化、可扩展检测。
- 提供一种实用且可扩展的框架,通过有针对性的查询合成提升DBMS的鲁棒性。
提出的方法
- 通过构建在基准行上计算结果为TRUE的WHERE和JOIN子句,生成保证包含随机选择的“基准行”的SQL查询。
- 采用基于约束的合成技术,动态修改表达式,使其在应用于基准行时计算结果为TRUE,从而确保该行必然出现在结果集中。
- 该方法采用包含性预言机:若DBMS未能返回基准行,则检测到逻辑错误。
- 该方法已实现为名为SQLancer的工具,通过适配其特定的SQL方言和功能,支持多种DBMS。
- 通过结合随机查询生成与语义约束,确保预言机的正确性,而无需系统间共享语义。
- 该方法辅以触发内部错误(如数据损坏、崩溃)并利用副作用检测这些错误的技术。
实验结果
研究问题
- RQ1能否设计一种通用、轻量级的预言机,无需依赖差异测试,即可检测DBMS中的逻辑错误?
- RQ2基准行查询合成能否有效发现现有模糊测试和随机查询生成技术未能检测到的逻辑错误?
- RQ3该方法在具有不同SQL方言和特性的多样化、成熟DBMS中可扩展到何种程度?
- RQ4包含性预言机在检测生产级DBMS中先前未知的逻辑错误方面有多高效?
- RQ5该方法能否扩展至检测复杂SQL结构(如聚合函数和集合运算)中的错误?
主要发现
- 该方法在三种广泛使用的DBMS中发现了123个错误:SQLite中65个,MySQL中25个,PostgreSQL中9个。
- 其中99个错误经开发人员确认或修复,包括61个通过包含性预言机检测到,34个通过内部错误(如数据库损坏)检测到。
- 一个MySQL崩溃被归类为安全漏洞(CVE-2019-2879)。
- 该方法成功检测到一个自2013年以来长期存在且此前未被现有工具发现的SQLite关键逻辑错误。
- 该方法即使在DBMS特定功能(如SQLite的动态类型和部分索引)上也表现出有效性,而这些功能在其他DBMS中并不支持。
- 该方法的简洁性和通用性使其在无需共享语义或复杂预言机的前提下,广泛适用于各类DBMS。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。