]> 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 ce5f2a5e833b9b8a6601860e0761ac3a4859340c..bdb71e5e17ae293e2775e18683021f32e78616b0 100644 (file)
@@ -187,6 +187,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 b9d473499d36e56b7239acdbb5e8d21aab210cfc..417da1397323f800c4b08efd810d80662372d3c9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,8 +31,8 @@ Library
 
 - Issue #27760: Fix possible integer overflow in binascii.b2a_qp.
 
-- 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 #27758: Fix possible integer overflow in the _csv module for large record
   lengths.
index d0d747986dc77640a0be2d97492abe41a97627a9..e478a5794829be82988100c679738b455cd325c5 100644 (file)
@@ -1095,6 +1095,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,MIN(n,1023));
         break;
     case 2:
@@ -1105,6 +1109,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, MIN(n,1023));
         break;
     default: