From ff672277ff5c215485310a2436f40bd35f8fe2c7 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 28 May 2017 19:03:08 +0100 Subject: [PATCH 1/1] pubkey.c (dsa_setup): Make sure `u' is None or an MP object. Organization: Straylight/Edgeware From: Mark Wooding Don't just store the caller's object and hope for the best. --- pubkey.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pubkey.c b/pubkey.c index 90a29b3..5167a97 100644 --- a/pubkey.c +++ b/pubkey.c @@ -65,8 +65,12 @@ static PyObject *dsa_setup(PyTypeObject *ty, PyObject *G, PyObject *u, if (!u) { g->d.u = 0; u = Py_None; - } else if ((g->d.u = getmp(u)) == 0) - goto end; + } else { + if ((g->d.u = getmp(u)) == 0) + goto end; + if (MP_PYCHECK(u)) Py_INCREF(u); + else u = mp_pywrap(g->d.u); + } if (!p) { assert(g->d.u); assert(calcpub); pp = G_CREATE(GROUP_G(G)); @@ -78,7 +82,7 @@ static PyObject *dsa_setup(PyTypeObject *ty, PyObject *G, PyObject *u, g->d.p = GE_X(p); g->d.r = GRAND_R(rng); g->d.h = GCHASH_CH(hash); - g->G = G; Py_INCREF(G); g->u = u; Py_INCREF(u); g->p = p; + g->G = G; Py_INCREF(G); g->u = u; g->p = p; g->rng = rng; Py_INCREF(rng); g->hash = hash; Py_INCREF(hash); return ((PyObject *)g); end: -- [mdw]