gh-111178: fix UBSan failures in Modules/_sqlite (GH-129087)

* fix UBSan failures for `pysqlite_Blob`
* fix UBSan failures for `pysqlite_Connection`
* fix UBSan failures for `pysqlite_Cursor`
* fix UBSan failures for `pysqlite_PrepareProtocol`
* fix UBSan failures for `pysqlite_Row`
* fix UBSan failures for `pysqlite_Statement`

* suppress unused return values
This commit is contained in:
Bénédikt Tran 2025-01-31 14:33:30 +01:00 committed by GitHub
parent 9d63ae5fe5
commit 881984b41a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 101 additions and 55 deletions

View file

@ -9,6 +9,8 @@
#include "clinic/blob.c.h"
#undef clinic_state
#define _pysqlite_Blob_CAST(op) ((pysqlite_Blob *)(op))
/*[clinic input]
module _sqlite3
class _sqlite3.Blob "pysqlite_Blob *" "clinic_state()->BlobType"
@ -29,32 +31,35 @@ close_blob(pysqlite_Blob *self)
}
static int
blob_traverse(pysqlite_Blob *self, visitproc visit, void *arg)
blob_traverse(PyObject *op, visitproc visit, void *arg)
{
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->connection);
return 0;
}
static int
blob_clear(pysqlite_Blob *self)
blob_clear(PyObject *op)
{
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
Py_CLEAR(self->connection);
return 0;
}
static void
blob_dealloc(pysqlite_Blob *self)
blob_dealloc(PyObject *op)
{
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
close_blob(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);
}
@ -373,8 +378,9 @@ blob_exit_impl(pysqlite_Blob *self, PyObject *type, PyObject *val,
}
static Py_ssize_t
blob_length(pysqlite_Blob *self)
blob_length(PyObject *op)
{
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
if (!check_blob(self)) {
return -1;
}
@ -449,8 +455,9 @@ subscript_slice(pysqlite_Blob *self, PyObject *item)
}
static PyObject *
blob_subscript(pysqlite_Blob *self, PyObject *item)
blob_subscript(PyObject *op, PyObject *item)
{
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
if (!check_blob(self)) {
return NULL;
}
@ -546,8 +553,9 @@ ass_subscript_slice(pysqlite_Blob *self, PyObject *item, PyObject *value)
}
static int
blob_ass_subscript(pysqlite_Blob *self, PyObject *item, PyObject *value)
blob_ass_subscript(PyObject *op, PyObject *item, PyObject *value)
{
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
if (!check_blob(self)) {
return -1;
}