From: Benjamin Peterson Date: Tue, 16 Aug 2016 04:40:14 +0000 (-0700) Subject: fail when negative values are passed to instr() X-Git-Tag: v3.6.0b1~713^2^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=432ea4ff375f920fa4a469d34e5dad56fb33f915;p=python fail when negative values are passed to instr() --- diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py index f049c29c6b..379721a9ae 100644 --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -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): diff --git a/Misc/NEWS b/Misc/NEWS index 4e457f0c76..bff6e00a12 100644 --- 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. diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index a8735f237a..501ec91869 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -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: