Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix UBSan failures for pysqlite_Cursor
  • Loading branch information
picnixz committed Jan 20, 2025
commit 280a89fc094498aba16c38d7b1d2adffe8680fcb
24 changes: 14 additions & 10 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ stmt_reset(pysqlite_Statement *self)
}

static int
cursor_traverse(pysqlite_Cursor *self, visitproc visit, void *arg)
cursor_traverse(PyObject *op, visitproc visit, void *arg)
{
pysqlite_Cursor *self = _pysqlite_Cursor_CAST(op);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->connection);
Py_VISIT(self->description);
Expand All @@ -159,8 +160,9 @@ cursor_traverse(pysqlite_Cursor *self, visitproc visit, void *arg)
}

static int
cursor_clear(pysqlite_Cursor *self)
cursor_clear(PyObject *op)
{
pysqlite_Cursor *self = _pysqlite_Cursor_CAST(op);
Py_CLEAR(self->connection);
Py_CLEAR(self->description);
Py_CLEAR(self->row_cast_map);
Expand All @@ -176,14 +178,15 @@ cursor_clear(pysqlite_Cursor *self)
}

static void
cursor_dealloc(pysqlite_Cursor *self)
cursor_dealloc(PyObject *op)
{
pysqlite_Cursor *self = _pysqlite_Cursor_CAST(op);
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
if (self->in_weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject*)self);
PyObject_ClearWeakRefs(op);
}
tp->tp_clear((PyObject *)self);
(void)tp->tp_clear(op);
tp->tp_free(self);
Py_DECREF(tp);
}
Expand Down Expand Up @@ -1087,8 +1090,9 @@ pysqlite_cursor_executescript_impl(pysqlite_Cursor *self,
}

static PyObject *
pysqlite_cursor_iternext(pysqlite_Cursor *self)
pysqlite_cursor_iternext(PyObject *op)
{
pysqlite_Cursor *self = _pysqlite_Cursor_CAST(op);
if (!check_cursor(self)) {
return NULL;
}
Expand Down Expand Up @@ -1125,7 +1129,7 @@ pysqlite_cursor_iternext(pysqlite_Cursor *self)
}
if (!Py_IsNone(self->row_factory)) {
PyObject *factory = self->row_factory;
PyObject *args[] = { (PyObject *)self, row, };
PyObject *args[] = { op, row, };
PyObject *new_row = PyObject_Vectorcall(factory, args, 2, NULL);
Py_SETREF(row, new_row);
}
Expand All @@ -1144,7 +1148,7 @@ pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self)
{
PyObject* row;

row = pysqlite_cursor_iternext(self);
row = pysqlite_cursor_iternext((PyObject *)self);
if (!row && !PyErr_Occurred()) {
Py_RETURN_NONE;
}
Expand Down Expand Up @@ -1174,7 +1178,7 @@ pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows)
return NULL;
}

while ((row = pysqlite_cursor_iternext(self))) {
while ((row = pysqlite_cursor_iternext((PyObject *)self))) {
if (PyList_Append(list, row) < 0) {
Py_DECREF(row);
break;
Expand Down Expand Up @@ -1212,7 +1216,7 @@ pysqlite_cursor_fetchall_impl(pysqlite_Cursor *self)
return NULL;
}

while ((row = pysqlite_cursor_iternext(self))) {
while ((row = pysqlite_cursor_iternext((PyObject *)self))) {
if (PyList_Append(list, row) < 0) {
Py_DECREF(row);
break;
Expand Down
2 changes: 2 additions & 0 deletions Modules/_sqlite/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ typedef struct
PyObject* in_weakreflist; /* List of weak references */
} pysqlite_Cursor;

#define _pysqlite_Cursor_CAST(op) ((pysqlite_Cursor *)(op))

int pysqlite_cursor_setup_types(PyObject *module);

#endif