python / python/cpython

sqlite3 Cursor NULL-deref via reentrant execute() inside a text_factory/converter during fetch

未关闭
#157,564 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

extension-modules topic-sqlite3 type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:
import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE t(a TEXT, b TEXT)")
con.execute("INSERT INTO t VALUES ('first', 'second')")
cur = con.cursor()
def btf(data):
    try:
        cur.execute("SELECT 1")            
    except sqlite3.ProgrammingError:
        pass                              
    return bytes(data).decode()
con.text_factory = btf
cur.execute("SELECT a, b FROM t")
print(cur.fetchone())                  
Modules/_sqlite/cursor.c:402:23: runtime error: member access within null pointer of type 'struct pysqlite_Statement'
    #0 _pysqlite_fetch_one_row Modules/_sqlite/cursor.c:402
    #1 pysqlite_cursor_iternext Modules/_sqlite/cursor.c:1155
    #2 pysqlite_cursor_fetchone_impl Modules/_sqlite/cursor.c:1206
    #3 pysqlite_cursor_fetchone Modules/_sqlite/clinic/cursor.c.h:169
CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-157578

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Modules/_sqlite/cursor.c 开始,尤其是 402 行附近的 _pysqlite_fetch_one_row,并使用所示的 text_factory 回调在 sanitizer 下复现该报告。跟踪可重入的 cur.execute() 如何在获取过程中影响该语句;完成的标准是复现器不再触发空指针解引用,并在现有的关联工作旁添加适当的覆盖率。

由索引模型根据 Issue 内容生成。

评估

技术栈
python, sqlite
领域
databases
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。