do not allow reading negative values with getstr()
This commit is contained in:
parent
59b6abd38c
commit
40a77c3381
|
@ -163,6 +163,9 @@ class TestCurses(unittest.TestCase):
|
||||||
if hasattr(curses, 'enclose'):
|
if hasattr(curses, 'enclose'):
|
||||||
stdscr.enclose()
|
stdscr.enclose()
|
||||||
|
|
||||||
|
self.assertRaises(ValueError, stdscr.getstr, -400)
|
||||||
|
self.assertRaises(ValueError, stdscr.getstr, 2, 3, -400)
|
||||||
|
|
||||||
|
|
||||||
def test_module_funcs(self):
|
def test_module_funcs(self):
|
||||||
"Test module-level functions"
|
"Test module-level functions"
|
||||||
|
|
|
@ -13,6 +13,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- In the curses module, raise an error if window.getstr() is passed a negative
|
||||||
|
value.
|
||||||
|
|
||||||
- Issue #27758: Fix possible integer overflow in the _csv module for large record
|
- Issue #27758: Fix possible integer overflow in the _csv module for large record
|
||||||
lengths.
|
lengths.
|
||||||
|
|
||||||
|
|
|
@ -1284,6 +1284,10 @@ PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
|
||||||
case 1:
|
case 1:
|
||||||
if (!PyArg_ParseTuple(args,"i;n", &n))
|
if (!PyArg_ParseTuple(args,"i;n", &n))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (n < 0) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023));
|
rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023));
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
@ -1302,6 +1306,10 @@ PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
|
||||||
case 3:
|
case 3:
|
||||||
if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
|
if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (n < 0) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
#ifdef STRICT_SYSV_CURSES
|
#ifdef STRICT_SYSV_CURSES
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
rtn2 = wmove(self->win,y,x)==ERR ? ERR :
|
rtn2 = wmove(self->win,y,x)==ERR ? ERR :
|
||||||
|
|
Loading…
Reference in New Issue