summaryrefslogtreecommitdiff
path: root/Modules/md5module.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2009-02-12 07:35:29 +0000
committerGregory P. Smith <greg@mad-scientist.com>2009-02-12 07:35:29 +0000
commit5eac8693e162ad8319ac06ddc79914cddf39a378 (patch)
tree34744a86d743ef1b08b39e51cebcb5e9253709a1 /Modules/md5module.c
parent6aba1d8763d85a7c9be7447c6221ce14db0616d5 (diff)
downloadcpython-5eac8693e162ad8319ac06ddc79914cddf39a378.tar.gz
Fixes Issue #3745: Fix hashlib to always reject unicode and non
buffer-api supporting objects as input no matter how it was compiled (built in implementations or external openssl library).
Diffstat (limited to 'Modules/md5module.c')
-rw-r--r--Modules/md5module.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 3d54131dec..ac98433831 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -17,6 +17,7 @@
/* MD5 objects */
#include "Python.h"
+#include "hashlib.h"
/* Some useful types */
@@ -411,11 +412,14 @@ PyDoc_STRVAR(MD5_update__doc__,
static PyObject *
MD5_update(MD5object *self, PyObject *args)
{
+ PyObject *obj;
Py_buffer buf;
- if (!PyArg_ParseTuple(args, "s*:update", &buf))
+ if (!PyArg_ParseTuple(args, "O:update", &obj))
return NULL;
+ GET_BUFFER_VIEW_OR_ERROUT(obj, &buf);
+
md5_process(&self->hash_state, buf.buf, buf.len);
PyBuffer_Release(&buf);
@@ -511,14 +515,17 @@ MD5_new(PyObject *self, PyObject *args, PyObject *kwdict)
{
static char *kwlist[] = {"string", NULL};
MD5object *new;
+ PyObject *data_obj = NULL;
Py_buffer buf;
- buf.buf = NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
- &buf)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist,
+ &data_obj)) {
return NULL;
}
+ if (data_obj)
+ GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf);
+
if ((new = newMD5object()) == NULL)
return NULL;
@@ -528,7 +535,7 @@ MD5_new(PyObject *self, PyObject *args, PyObject *kwdict)
Py_DECREF(new);
return NULL;
}
- if (buf.buf) {
+ if (data_obj) {
md5_process(&new->hash_state, buf.buf, buf.len);
PyBuffer_Release(&buf);
}