Commit 8699950b authored by Victor Stinner's avatar Victor Stinner

Issue #6697: Check that _PyUnicode_AsString() result is not NULL in _sqlite

Strip also some trailing spaces
parent f6c57832
...@@ -495,7 +495,9 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val) ...@@ -495,7 +495,9 @@ void _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
} else if (PyFloat_Check(py_val)) { } else if (PyFloat_Check(py_val)) {
sqlite3_result_double(context, PyFloat_AsDouble(py_val)); sqlite3_result_double(context, PyFloat_AsDouble(py_val));
} else if (PyUnicode_Check(py_val)) { } else if (PyUnicode_Check(py_val)) {
sqlite3_result_text(context, _PyUnicode_AsString(py_val), -1, SQLITE_TRANSIENT); char *str = _PyUnicode_AsString(py_val);
if (str != NULL)
sqlite3_result_text(context, str, -1, SQLITE_TRANSIENT);
} else if (PyObject_CheckBuffer(py_val)) { } else if (PyObject_CheckBuffer(py_val)) {
if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) { if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) {
PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
......
...@@ -533,7 +533,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* ...@@ -533,7 +533,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
} }
operation_cstr = _PyUnicode_AsStringAndSize(operation, &operation_len); operation_cstr = _PyUnicode_AsStringAndSize(operation, &operation_len);
if (operation == NULL) if (operation_cstr == NULL)
goto error; goto error;
/* reset description and rowcount */ /* reset description and rowcount */
......
...@@ -83,6 +83,8 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx) ...@@ -83,6 +83,8 @@ PyObject* pysqlite_row_subscript(pysqlite_Row* self, PyObject* idx)
return item; return item;
} else if (PyUnicode_Check(idx)) { } else if (PyUnicode_Check(idx)) {
key = _PyUnicode_AsString(idx); key = _PyUnicode_AsString(idx);
if (key == NULL)
return NULL;
nitems = PyTuple_Size(self->description); nitems = PyTuple_Size(self->description);
......
...@@ -130,7 +130,10 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec ...@@ -130,7 +130,10 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
break; break;
case TYPE_UNICODE: case TYPE_UNICODE:
string = _PyUnicode_AsString(parameter); string = _PyUnicode_AsString(parameter);
if (string != NULL)
rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
else
rc = -1;
break; break;
case TYPE_BUFFER: case TYPE_BUFFER:
if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) { if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment