ec.c (eccurve_pyrichcompare): Check that second operand has correct type.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 18 Oct 2019 21:15:46 +0000 (22:15 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 17 Nov 2019 02:50:40 +0000 (02:50 +0000)
A segfault waiting to happen, which has been lurking since the
beginning.

ec.c

diff --git a/ec.c b/ec.c
index c8cdebe..0df218b 100644 (file)
--- 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;