ec.c: Reject strings with trailing junk in the curve-point constructor.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 24 Nov 2019 21:54:44 +0000 (21:54 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 11 Apr 2020 11:49:31 +0000 (12:49 +0100)
ec.c
t/t-ec.py

diff --git a/ec.c b/ec.c
index 444af3b..47445c1 100644 (file)
--- a/ec.c
+++ b/ec.c
@@ -525,6 +525,7 @@ static int ecptxl_1(ec_curve *c, ec *p, PyObject *x)
     qd.e = 0;
     if (!ec_ptparse(&qd, p))
       VALERR(qd.e);
+    qd_skipspc(&qd); if (!qd_eofp(&qd)) VALERR("junk at eof");
     goto fix;
   } else if (c && (xx = tomp(x)) != 0) {
     xx = F_IN(c->f, xx, xx);
index 75dc2be..02ae4d1 100644 (file)
--- a/t/t-ec.py
+++ b/t/t-ec.py
@@ -59,6 +59,7 @@ class TestCurvelessPoints (U.TestCase):
     me.assertRaises(ValueError, C.ECPt, "12345")
     me.assertRaises(ValueError, C.ECPt, "12345,")
     me.assertRaises(ValueError, C.ECPt, "12345, xyzzy")
+    me.assertRaises(ValueError, C.ECPt, "12345, 67890!??")
     me.assertRaises(TypeError, C.ECPt, (1, 2, 3))
     me.assertRaises(TypeError, C.ECPt, 1, 2, 3)
     me.assertRaises(TypeError, C.ECPt, 1234)
@@ -144,6 +145,7 @@ class TestCurves (T.GenericTestMixin):
     me.assertEqual(E("%s, %s" % (P.ix, P.iy)), P)
     me.assertRaises(ValueError, E, "1234")
     me.assertRaises(ValueError, E, "1234,")
+    me.assertRaises(ValueError, E, "1234, 5678?")
     me.assertRaises(TypeError, E, 1, None)
     Q = E(P.ix); me.assertTrue(Q == P or Q == -P)
     for i in T.range(128):