# HG changeset patch # User ralf@brainbot.com # Date 1216073395 -7200 # Branch hashopenssl-3026 # Node ID ed68f74ccf91f3439fb7e8767c64c5a1d18e6cc9 # Parent 09ae2c8f2d752b94ee5357aa370c655b9a9883ce fix for http://bugs.python.org/issue3026 diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c --- a/Modules/_hashopenssl.c +++ b/Modules/_hashopenssl.c @@ -152,6 +152,21 @@ return retval; } +/* call EVP_DigestUpdate and check for signal */ +static int digest_update(EVP_MD_CTX *ctx, const unsigned char *d, Py_ssize_t cnt) +{ + unsigned int this_count; + while ( this_count = cnt>0x1000000 ? 0x1000000 : cnt) { + EVP_DigestUpdate(ctx, d, this_count); + d += this_count; + cnt -= this_count; + if (PyErr_CheckSignals()) { + return 0; + } + } + return 1; +} + PyDoc_STRVAR(EVP_update__doc__, "Update this hash object's state with the provided string."); @@ -163,9 +178,9 @@ if (!PyArg_ParseTuple(args, "s#:update", &cp, &len)) return NULL; - - EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, - unsigned int)); + if (!digest_update(&self->ctx, cp, len)) { + return NULL; + } Py_INCREF(Py_None); return Py_None; @@ -255,10 +270,11 @@ self->name = name_obj; Py_INCREF(self->name); - if (cp && len) - EVP_DigestUpdate(&self->ctx, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, - unsigned int)); - + if (cp && len) { + if (!digest_update(&self->ctx, cp, len)) { + return -1; + } + } return 0; } #endif @@ -327,7 +343,7 @@ static PyObject * EVPnew(PyObject *name_obj, const EVP_MD *digest, const EVP_MD_CTX *initial_ctx, - const unsigned char *cp, unsigned int len) + const unsigned char *cp, Py_ssize_t len) { EVPobject *self; @@ -345,8 +361,12 @@ EVP_DigestInit(&self->ctx, digest); } - if (cp && len) - EVP_DigestUpdate(&self->ctx, cp, len); + if (cp && len) { + if (!digest_update(&self->ctx, cp, len)) { + EVP_dealloc(self); + return NULL; + } + } return (PyObject *)self; } @@ -383,8 +403,7 @@ digest = EVP_get_digestbyname(name); - return EVPnew(name_obj, digest, NULL, cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, - unsigned int)); + return EVPnew(name_obj, digest, NULL, cp, len); } /* @@ -409,7 +428,7 @@ CONST_ ## NAME ## _name_obj, \ NULL, \ CONST_new_ ## NAME ## _ctx_p, \ - cp, Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int)); \ + cp, len); \ } /* a PyMethodDef structure for the constructor */