summaryrefslogtreecommitdiffstats
path: root/Modules/sha1module.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2009-02-12 07:35:29 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2009-02-12 07:35:29 (GMT)
commit365a1864fd285fc6ee9d9fa1f8770b39d4dab830 (patch)
tree0fb2cf9664348d80caa3e3ace86b84aa2a3f9080 /Modules/sha1module.c
parent3072921d0e668e890da1312e0f47f3e7e4854329 (diff)
downloadcpython-365a1864fd285fc6ee9d9fa1f8770b39d4dab830.zip
cpython-365a1864fd285fc6ee9d9fa1f8770b39d4dab830.tar.gz
cpython-365a1864fd285fc6ee9d9fa1f8770b39d4dab830.tar.bz2
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/sha1module.c')
-rw-r--r--Modules/sha1module.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/Modules/sha1module.c b/Modules/sha1module.c
index 4d8ed1d..a7f6ad2 100644
--- a/Modules/sha1module.c
+++ b/Modules/sha1module.c
@@ -17,6 +17,7 @@
/* SHA1 objects */
#include "Python.h"
+#include "hashlib.h"
/* Some useful types */
@@ -387,11 +388,14 @@ PyDoc_STRVAR(SHA1_update__doc__,
static PyObject *
SHA1_update(SHA1object *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);
+
sha1_process(&self->hash_state, buf.buf, buf.len);
PyBuffer_Release(&buf);
@@ -487,14 +491,17 @@ SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict)
{
static char *kwlist[] = {"string", NULL};
SHA1object *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 = newSHA1object()) == NULL)
return NULL;
@@ -504,7 +511,7 @@ SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict)
Py_DECREF(new);
return NULL;
}
- if (buf.buf) {
+ if (data_obj) {
sha1_process(&new->hash_state, buf.buf, buf.len);
PyBuffer_Release(&buf);
}