diff options
author | Andrew M. Kuchling <amk@amk.ca> | 2000-12-15 00:59:32 (GMT) |
---|---|---|
committer | Andrew M. Kuchling <amk@amk.ca> | 2000-12-15 00:59:32 (GMT) |
commit | 2e09530f3fed8cf280f1c606c0c1a362b222fdbc (patch) | |
tree | a6010ed8a7071a86d4e085dfccbbbd346222b455 /Modules/bsddbmodule.c | |
parent | 2824d7f6b1f506371a3d63ec83e1981f3ec221d5 (diff) | |
download | cpython-2e09530f3fed8cf280f1c606c0c1a362b222fdbc.zip cpython-2e09530f3fed8cf280f1c606c0c1a362b222fdbc.tar.gz cpython-2e09530f3fed8cf280f1c606c0c1a362b222fdbc.tar.bz2 |
[Patch #102827] Fix for PR#119558, avoiding core dumps by checking for
malloc() returning NULL
Diffstat (limited to 'Modules/bsddbmodule.c')
-rw-r--r-- | Modules/bsddbmodule.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Modules/bsddbmodule.c b/Modules/bsddbmodule.c index 24d859b..35a22b9 100644 --- a/Modules/bsddbmodule.c +++ b/Modules/bsddbmodule.c @@ -266,9 +266,10 @@ bsddb_subscript(bsddbobject *dp, PyObject *key) if (status == 0) { if (drec.size > sizeof(buf)) data = malloc(drec.size); else data = buf; - memcpy(data,drec.data,drec.size); + if (data!=NULL) memcpy(data,drec.data,drec.size); } BSDDB_END_SAVE(dp) + if (data==NULL) return PyErr_NoMemory(); if (status != 0) { if (status < 0) PyErr_SetFromErrno(BsddbError); @@ -387,9 +388,10 @@ bsddb_keys(bsddbobject *dp, PyObject *args) if (status == 0) { if (krec.size > sizeof(buf)) data = malloc(krec.size); else data = buf; - memcpy(data,krec.data,krec.size); + if (data!=NULL) memcpy(data,krec.data,krec.size); } BSDDB_END_SAVE(dp) + if (data==NULL) return PyErr_NoMemory(); while (status == 0) { item = PyString_FromStringAndSize(data, (int)krec.size); if (data != buf) free(data); @@ -408,9 +410,10 @@ bsddb_keys(bsddbobject *dp, PyObject *args) if (status == 0) { if (krec.size > sizeof(buf)) data = malloc(krec.size); else data = buf; - memcpy(data,krec.data,krec.size); + if (data!=NULL) memcpy(data,krec.data,krec.size); } BSDDB_END_SAVE(dp) + if (data==NULL) return PyErr_NoMemory(); } if (status < 0) { PyErr_SetFromErrno(BsddbError); @@ -467,9 +470,10 @@ bsddb_set_location(bsddbobject *dp, PyObject *key) if (status == 0) { if (drec.size > sizeof(buf)) data = malloc(drec.size); else data = buf; - memcpy(data,drec.data,drec.size); + if (data!=NULL) memcpy(data,drec.data,drec.size); } BSDDB_END_SAVE(dp) + if (data==NULL) return PyErr_NoMemory(); if (status != 0) { if (status < 0) PyErr_SetFromErrno(BsddbError); @@ -505,13 +509,18 @@ bsddb_seq(bsddbobject *dp, PyObject *args, int sequence_request) if (status == 0) { if (krec.size > sizeof(kbuf)) kdata = malloc(krec.size); else kdata = kbuf; - memcpy(kdata,krec.data,krec.size); + if (kdata!=NULL) memcpy(kdata,krec.data,krec.size); if (drec.size > sizeof(dbuf)) ddata = malloc(drec.size); else ddata = dbuf; - memcpy(ddata,drec.data,drec.size); + if (ddata!=NULL) memcpy(ddata,drec.data,drec.size); } BSDDB_END_SAVE(dp) - if (status != 0) { + if (status == 0) { + if ((kdata==NULL) || (ddata==NULL)) + return PyErr_NoMemory(); + } + else { + /* (status != 0) */ if (status < 0) PyErr_SetFromErrno(BsddbError); else |