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
Pass -1 if size >= INT_MAX
  • Loading branch information
Erlend E. Aasland committed May 19, 2021
commit 9febd15380ac41ba724cb33d4d01a509a3a37603
9 changes: 4 additions & 5 deletions Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
const char* script_cstr;
sqlite3_stmt* statement;
int rc;
Py_ssize_t script_length;
Py_ssize_t sql_len;
PyObject* result;

if (!check_cursor(self)) {
Expand All @@ -691,7 +691,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
self->reset = 0;

if (PyUnicode_Check(script_obj)) {
script_cstr = PyUnicode_AsUTF8AndSize(script_obj, &script_length);
script_cstr = PyUnicode_AsUTF8AndSize(script_obj, &sql_len);
if (!script_cstr) {
return NULL;
}
Expand All @@ -707,14 +707,13 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
}
Py_DECREF(result);

Py_ssize_t size_incl_null = script_length + 1;
while (1) {
const char *tail;

Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare_v2(self->connection->db,
script_cstr,
size_incl_null,
(sql_len >= INT_MAX) ? -1 : (int)sql_len + 1,
&statement,
&tail);
Py_END_ALLOW_THREADS
Expand Down Expand Up @@ -747,7 +746,7 @@ pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
if (*tail == (char)0) {
break;
}
size_incl_null -= (tail - script_cstr);
sql_len -= (tail - script_cstr);
script_cstr = tail;
}

Expand Down
8 changes: 7 additions & 1 deletion Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con
break;
}

if (sql_cstr_len >= INT_MAX) {
sql_cstr_len = -1;
}
else {
sql_cstr_len += 1;
}
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare_v2(connection->db,
sql_cstr,
sql_cstr_len + 1,
(int)sql_cstr_len,
&self->st,
&tail);
Py_END_ALLOW_THREADS
Expand Down