python2/fix-dbm_contains-on-64bit-bigendian.patch

26 lines
799 B
Diff

Index: Modules/dbmmodule.c
===================================================================
--- Modules/dbmmodule.c (revision 84317)
+++ Modules/dbmmodule.c (working copy)
@@ -168,12 +168,18 @@
dbm_contains(register dbmobject *dp, PyObject *v)
{
datum key, val;
+ Py_ssize_t dsize;
- if (PyString_AsStringAndSize(v, (char **)&key.dptr,
- (Py_ssize_t *)&key.dsize)) {
+ if (PyString_AsStringAndSize(v, (char **)&key.dptr, &dsize)) {
return -1;
}
+ /* Coerce from Py_ssize_t down to int: */
+ if (dsize > INT_MAX) {
+ return -1;
+ }
+ key.dsize = dsize;
+
/* Expand check_dbmobject_open to return -1 */
if (dp->di_dbm == NULL) {
PyErr_SetString(DbmError, "DBM object has already been closed");