diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-11-18 00:36:29 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-11-18 00:36:29 (GMT) |
commit | 3f658bec35c3985355d001ac4dcfb64a4de7ca93 (patch) | |
tree | b84a474aece8fe9d26563231dea78c5b61e29aee /Modules/_sqlite/statement.c | |
parent | 83e30bf4bda30153bb2e5dc881fb540e7411deb1 (diff) | |
download | cpython-3f658bec35c3985355d001ac4dcfb64a4de7ca93.zip cpython-3f658bec35c3985355d001ac4dcfb64a4de7ca93.tar.gz cpython-3f658bec35c3985355d001ac4dcfb64a4de7ca93.tar.bz2 |
sqlite: raise an OverflowError if a string or a BLOB is longer than INT_MAX
bytes
Fix compiler warnings on Windows 64-bit
Diffstat (limited to 'Modules/_sqlite/statement.c')
-rw-r--r-- | Modules/_sqlite/statement.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index b056d8b..6cc0e16 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -132,18 +132,26 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec break; case TYPE_UNICODE: string = _PyUnicode_AsStringAndSize(parameter, &buflen); - if (string != NULL) - rc = sqlite3_bind_text(self->st, pos, string, buflen, SQLITE_TRANSIENT); - else - rc = -1; + if (string == NULL) + return -1; + if (buflen > INT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "string longer than INT_MAX bytes"); + return -1; + } + rc = sqlite3_bind_text(self->st, pos, string, (int)buflen, SQLITE_TRANSIENT); break; case TYPE_BUFFER: - if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) { - rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT); - } else { + if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) != 0) { PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); - rc = -1; + return -1; + } + if (buflen > INT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "BLOB longer than INT_MAX bytes"); + return -1; } + rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT); break; case TYPE_UNKNOWN: rc = -1; |