Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b9cb25

Browse files
committed
Use s* to receive data. Fixes #3552.
1 parent 42b2f2e commit 7b9cb25

2 files changed

Lines changed: 24 additions & 21 deletions

File tree

Modules/md5module.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,14 @@ PyDoc_STRVAR(MD5_update__doc__,
411411
static PyObject *
412412
MD5_update(MD5object *self, PyObject *args)
413413
{
414-
unsigned char *cp;
415-
int len;
416-
417-
if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
414+
Py_buffer buf;
415+
416+
if (!PyArg_ParseTuple(args, "s*:update", &buf))
418417
return NULL;
419418

420-
md5_process(&self->hash_state, cp, len);
419+
md5_process(&self->hash_state, buf.buf, buf.len);
421420

421+
PyBuffer_Release(&buf);
422422
Py_INCREF(Py_None);
423423
return Py_None;
424424
}
@@ -511,11 +511,11 @@ MD5_new(PyObject *self, PyObject *args, PyObject *kwdict)
511511
{
512512
static char *kwlist[] = {"string", NULL};
513513
MD5object *new;
514-
unsigned char *cp = NULL;
515-
int len;
514+
Py_buffer buf;
515+
buf.buf = NULL;
516516

517-
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s#:new", kwlist,
518-
&cp, &len)) {
517+
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
518+
&buf)) {
519519
return NULL;
520520
}
521521

@@ -528,8 +528,10 @@ MD5_new(PyObject *self, PyObject *args, PyObject *kwdict)
528528
Py_DECREF(new);
529529
return NULL;
530530
}
531-
if (cp)
532-
md5_process(&new->hash_state, cp, len);
531+
if (buf.buf) {
532+
md5_process(&new->hash_state, buf.buf, buf.len);
533+
PyBuffer_Release(&buf);
534+
}
533535

534536
return (PyObject *)new;
535537
}

Modules/sha1module.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,14 @@ PyDoc_STRVAR(SHA1_update__doc__,
387387
static PyObject *
388388
SHA1_update(SHA1object *self, PyObject *args)
389389
{
390-
unsigned char *cp;
391-
int len;
390+
Py_buffer buf;
392391

393-
if (!PyArg_ParseTuple(args, "s#:update", &cp, &len))
392+
if (!PyArg_ParseTuple(args, "s*:update", &buf))
394393
return NULL;
395394

396-
sha1_process(&self->hash_state, cp, len);
395+
sha1_process(&self->hash_state, buf.buf, buf.len);
397396

397+
PyBuffer_Release(&buf);
398398
Py_INCREF(Py_None);
399399
return Py_None;
400400
}
@@ -487,11 +487,10 @@ SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict)
487487
{
488488
static char *kwlist[] = {"string", NULL};
489489
SHA1object *new;
490-
unsigned char *cp = NULL;
491-
int len;
490+
Py_buffer buf;
492491

493-
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s#:new", kwlist,
494-
&cp, &len)) {
492+
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|s*:new", kwlist,
493+
&buf)) {
495494
return NULL;
496495
}
497496

@@ -504,8 +503,10 @@ SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict)
504503
Py_DECREF(new);
505504
return NULL;
506505
}
507-
if (cp)
508-
sha1_process(&new->hash_state, cp, len);
506+
if (buf.buf) {
507+
sha1_process(&new->hash_state, buf.buf, buf.len);
508+
PyBuffer_Release(&buf);
509+
}
509510

510511
return (PyObject *)new;
511512
}

0 commit comments

Comments
 (0)