From: Mark Wooding Date: Fri, 18 Oct 2019 21:15:46 +0000 (+0100) Subject: ec.c (eccurve_pyrichcompare): Check that second operand has correct type. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/7f8c2476ae775cfe27be5a216cebb6ad35432185 ec.c (eccurve_pyrichcompare): Check that second operand has correct type. A segfault waiting to happen, which has been lurking since the beginning. --- diff --git a/ec.c b/ec.c index c8cdebe..0df218b 100644 --- a/ec.c +++ b/ec.c @@ -788,7 +788,11 @@ static PyTypeObject ecptcurve_pytype_skel = { static PyObject *eccurve_pyrichcompare(PyObject *x, PyObject *y, int op) { - int b = ec_samep(ECCURVE_C(x), ECCURVE_C(y)); + int b; + + assert(ECCURVE_PYCHECK(x)); + if (!ECCURVE_PYCHECK(y)) RETURN_NOTIMPL; + b = ec_samep(ECCURVE_C(x), ECCURVE_C(y)); switch (op) { case Py_EQ: break; case Py_NE: b = !b; break;