[Python-checkins] r70119 - in python/trunk/Modules: md5module.c shamodule.c
kristjan.jonsson
python-checkins at python.org
Tue Mar 3 04:20:43 CET 2009
Author: kristjan.jonsson
Date: Tue Mar 3 04:20:42 2009
New Revision: 70119
Log:
Fix SHA_new and MD5_new, that would crash if not given initial data
Modified:
python/trunk/Modules/md5module.c
python/trunk/Modules/shamodule.c
Modified: python/trunk/Modules/md5module.c
==============================================================================
--- python/trunk/Modules/md5module.c (original)
+++ python/trunk/Modules/md5module.c Tue Mar 3 04:20:42 2009
@@ -272,19 +272,21 @@
if (!PyArg_ParseTuple(args, "|O:new", &data_obj))
return NULL;
- GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view, NULL);
+ if (data_obj)
+ GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view, NULL);
if ((md5p = newmd5object()) == NULL) {
- PyBuffer_Release(&view);
+ if (data_obj)
+ PyBuffer_Release(&view);
return NULL;
}
if (data_obj) {
md5_append(&md5p->md5, (unsigned char*)view.buf,
Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int));
+ PyBuffer_Release(&view);
}
-
- PyBuffer_Release(&view);
+
return (PyObject *)md5p;
}
Modified: python/trunk/Modules/shamodule.c
==============================================================================
--- python/trunk/Modules/shamodule.c (original)
+++ python/trunk/Modules/shamodule.c Tue Mar 3 04:20:42 2009
@@ -548,10 +548,12 @@
return NULL;
}
- GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view, NULL);
+ if (data_obj)
+ GET_BUFFER_VIEW_OR_ERROUT(data_obj, &view, NULL);
if ((new = newSHAobject()) == NULL) {
- PyBuffer_Release(&view);
+ if (data_obj)
+ PyBuffer_Release(&view);
return NULL;
}
@@ -559,15 +561,16 @@
if (PyErr_Occurred()) {
Py_DECREF(new);
- PyBuffer_Release(&view);
+ if (data_obj)
+ PyBuffer_Release(&view);
return NULL;
}
if (data_obj) {
sha_update(new, (unsigned char*)view.buf,
Py_SAFE_DOWNCAST(view.len, Py_ssize_t, unsigned int));
+ PyBuffer_Release(&view);
}
- PyBuffer_Release(&view);
return (PyObject *)new;
}
More information about the Python-checkins
mailing list