chiark / gitweb /
pubkey.c (dsa_setup): Make sure `u' is None or an MP object.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 28 May 2017 18:03:08 +0000 (19:03 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 15 Jun 2017 23:48:00 +0000 (00:48 +0100)
Don't just store the caller's object and hope for the best.

pubkey.c

index 90a29b3df5e5a5e8144d003644f52f37a116ea7e..5167a973791f1930f18b4b7831a6ce6d4aa240ea 100644 (file)
--- 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: