From 5e3d862392acc3b6862c6393bfbca7450523717d Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Mon, 9 Jan 2006 06:24:35 +0000 Subject: [PATCH] Bug #1400115, Fix segfault when calling curses.panel.userptr() without prior setting of the userptr. Will backport. --- Lib/test/test_curses.py | 11 +++++++++++ Misc/NEWS | 3 +++ Modules/_curses_panel.c | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py index e137d318a8b..6f843ad6000 100644 --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -9,6 +9,7 @@ # import curses, sys, tempfile, os +import curses.panel # Optionally test curses module. This currently requires that the # 'curses' resource be given on the regrtest command line using the -u @@ -213,12 +214,22 @@ def unit_tests(): print 'curses.unctrl fails on character', repr(ch) +def test_userptr_without_set(stdscr): + w = curses.newwin(10, 10) + p = curses.panel.new_panel(w) + # try to access userptr() before calling set_userptr() -- segfaults + try: + p.userptr() + raise RuntimeError, 'userptr should fail since not set' + except curses.panel.error: + pass def main(stdscr): curses.savetty() try: module_funcs(stdscr) window_funcs(stdscr) + test_userptr_without_set(stdscr) finally: curses.resetty() diff --git a/Misc/NEWS b/Misc/NEWS index 3860fd332e4..2065ede0e41 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -209,6 +209,9 @@ Core and builtins Extension Modules ----------------- +- Bug #1400115, Fix segfault when calling curses.panel.userptr() + without prior setting of the userptr. + - Fix 64-bit problems in bsddb. - Patch #1365916: fix some unsafe 64-bit mmap methods. diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c index 08c5f09ade1..b5f30cb85ef 100644 --- a/Modules/_curses_panel.c +++ b/Modules/_curses_panel.c @@ -299,6 +299,11 @@ PyCursesPanel_userptr(PyCursesPanelObject *self) PyObject *obj; PyCursesInitialised; obj = (PyObject *) panel_userptr(self->pan); + if (obj == NULL) { + PyErr_SetString(PyCursesError, "no userptr set"); + return NULL; + } + Py_INCREF(obj); return obj; }