]> granicus.if.org Git - python/commitdiff
fail when negative values are passed to instr()
authorBenjamin Peterson <benjamin@python.org>
Tue, 16 Aug 2016 04:40:14 +0000 (21:40 -0700)
committerBenjamin Peterson <benjamin@python.org>
Tue, 16 Aug 2016 04:40:14 +0000 (21:40 -0700)
Lib/test/test_curses.py
Misc/NEWS
Modules/_cursesmodule.c

index f049c29c6b3d6c2616ab5943b08d0d395e09dcd3..379721a9aeab31644c20386fd0f5c9a55e558174 100644 (file)
@@ -165,6 +165,8 @@ class TestCurses(unittest.TestCase):
 
         self.assertRaises(ValueError, stdscr.getstr, -400)
         self.assertRaises(ValueError, stdscr.getstr, 2, 3, -400)
+        self.assertRaises(ValueError, stdscr.instr, -2)
+        self.assertRaises(ValueError, stdscr.instr, 2, 3, -2)
 
 
     def test_module_funcs(self):
index 4e457f0c76886b562f4ce4a40441eab9af8a6c50..bff6e00a12df6229de809dc07fb279a7680da8ab 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,8 +13,8 @@ Core and Builtins
 Library
 -------
 
-- In the curses module, raise an error if window.getstr() is passed a negative
-  value.
+- In the curses module, raise an error if window.getstr() or window.instr() is
+  passed a negative value.
 
 - Issue #27760: Fix possible integer overflow in binascii.b2a_qp.
 
index a8735f237a88126b23c81506bfd862e21ea1cd9c..501ec91869d90fb01f08254a8184762c500bf2a7 100644 (file)
@@ -1456,6 +1456,10 @@ PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
     case 1:
         if (!PyArg_ParseTuple(args,"i;n", &n))
             return NULL;
+        if (n < 0) {
+            PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
+            return NULL;
+        }
         rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023));
         break;
     case 2:
@@ -1466,6 +1470,10 @@ PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
     case 3:
         if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
             return NULL;
+        if (n < 0) {
+            PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
+            return NULL;
+        }
         rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023));
         break;
     default: