]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport:
authorNeal Norwitz <nnorwitz@gmail.com>
Mon, 9 Jan 2006 06:29:16 +0000 (06:29 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Mon, 9 Jan 2006 06:29:16 +0000 (06:29 +0000)
Bug #1400115, Fix segfault when calling curses.panel.userptr()
without prior setting of the userptr.

Lib/test/test_curses.py
Misc/NEWS
Modules/_curses_panel.c

index e137d318a8b16f76b9074182f62ccf606d3b9f3e..6f843ad60002967106fefe412f8ba274ee90a4bb 100644 (file)
@@ -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()
 
index 7d31df3b93e9497d256c2bbd2184caba93bce366..948e1ffefe0d31827962b54b6be9fa7921021678 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -193,6 +193,9 @@ Core and builtins
 Extension Modules
 -----------------
 
+- Bug #1400115, Fix segfault when calling curses.panel.userptr()
+  without prior setting of the userptr.
+
 - Bug #1346533, select.poll() doesn't raise an error if timeout > sys.maxint
 
 - Fix memory leak in posix.access().
index 08c5f09ade1930928492a0667addf8e705ff29c3..b5f30cb85efcbbe8156fef092ac3384a1e261f73 100644 (file)
@@ -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;
 }