mp.c: Check that CRT moduli are actually positive.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 10 Nov 2019 22:55:11 +0000 (22:55 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 22 Nov 2019 22:18:10 +0000 (22:18 +0000)
mp.c

diff --git a/mp.c b/mp.c
index a234c6d..77f7c3c 100644 (file)
--- a/mp.c
+++ b/mp.c
@@ -1737,6 +1737,7 @@ static PyObject *mpcrt_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
   for (i = 0; i < n; i++) {
     if ((x = PySequence_GetItem(q, i)) == 0) goto end;
     xx = getmp(x); Py_DECREF(x); if (!xx) goto end;
+    if (MP_CMP(xx, <=, MP_ZERO)) VALERR("moduli must be positive");
     v[i].m = xx; v[i].n = 0; v[i].ni = 0; v[i].nni = 0;
   }
   c = (mpcrt_pyobj *)ty->tp_alloc(ty, 0);