diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-04-14 21:09:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-14 21:09:11 (GMT) |
commit | 5cb601f956886b32641f818b5da347cc86a43db2 (patch) | |
tree | 4205f0ff5fced33357820c8382d8ca0ee5a0433d /Modules | |
parent | e07f4ab26aaf08f90ebd9e6004af14fd6ef39351 (diff) | |
download | cpython-5cb601f956886b32641f818b5da347cc86a43db2.zip cpython-5cb601f956886b32641f818b5da347cc86a43db2.tar.gz cpython-5cb601f956886b32641f818b5da347cc86a43db2.tar.bz2 |
bpo-43296: Handle sqlite3_value_blob() errors (GH-24674)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sqlite/connection.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 6d3ccb9..9336549 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -546,7 +546,6 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc, sqlite3_value* cur_value; PyObject* cur_py_value; const char* val_str; - Py_ssize_t buflen; args = PyTuple_New(argc); if (!args) { @@ -571,19 +570,26 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc, cur_py_value = Py_NewRef(Py_None); } break; - case SQLITE_BLOB: - buflen = sqlite3_value_bytes(cur_value); - cur_py_value = PyBytes_FromStringAndSize( - sqlite3_value_blob(cur_value), buflen); + case SQLITE_BLOB: { + sqlite3 *db = sqlite3_context_db_handle(context); + const void *blob = sqlite3_value_blob(cur_value); + + if (blob == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) { + PyErr_NoMemory(); + goto error; + } + + Py_ssize_t size = sqlite3_value_bytes(cur_value); + cur_py_value = PyBytes_FromStringAndSize(blob, size); break; + } case SQLITE_NULL: default: cur_py_value = Py_NewRef(Py_None); } if (!cur_py_value) { - Py_DECREF(args); - return NULL; + goto error; } PyTuple_SetItem(args, i, cur_py_value); @@ -591,6 +597,10 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc, } return args; + +error: + Py_DECREF(args); + return NULL; } static void |