bpo-43853: Handle sqlite3_value_text() errors (GH-25422)

(cherry picked from commit 006fd869e4)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
Miss Islington (bot) 2021-06-04 11:54:39 -07:00 committed by GitHub
parent 3f4d801bf9
commit 067d6d4657
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 13 deletions

View file

@ -576,7 +576,6 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc,
int i;
sqlite3_value* cur_value;
PyObject* cur_py_value;
const char* val_str;
args = PyTuple_New(argc);
if (!args) {
@ -592,15 +591,19 @@ _pysqlite_build_py_params(sqlite3_context *context, int argc,
case SQLITE_FLOAT:
cur_py_value = PyFloat_FromDouble(sqlite3_value_double(cur_value));
break;
case SQLITE_TEXT:
val_str = (const char*)sqlite3_value_text(cur_value);
cur_py_value = PyUnicode_FromString(val_str);
/* TODO: have a way to show errors here */
if (!cur_py_value) {
PyErr_Clear();
cur_py_value = Py_NewRef(Py_None);
case SQLITE_TEXT: {
sqlite3 *db = sqlite3_context_db_handle(context);
const char *text = (const char *)sqlite3_value_text(cur_value);
if (text == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) {
PyErr_NoMemory();
goto error;
}
Py_ssize_t size = sqlite3_value_bytes(cur_value);
cur_py_value = PyUnicode_FromStringAndSize(text, size);
break;
}
case SQLITE_BLOB: {
sqlite3 *db = sqlite3_context_db_handle(context);
const void *blob = sqlite3_value_blob(cur_value);