Mercurial > cpython-lru_cache-weakref
diff Modules/_sqlite/statement.c @ 87234:40d25b2b93f0
sqlite: raise an OverflowError if a string or a BLOB is longer than INT_MAX
bytes
Fix compiler warnings on Windows 64-bit
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Mon, 18 Nov 2013 01:36:29 +0100 |
| parents | 3055e61f1e66 |
| children | 2a01ca4b0edc |
line wrap: on
line diff
--- a/Modules/_sqlite/statement.c Mon Nov 18 01:27:30 2013 +0100 +++ b/Modules/_sqlite/statement.c Mon Nov 18 01:36:29 2013 +0100 @@ -132,18 +132,26 @@ 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;
