From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2273 invoked by alias); 7 Jul 2009 18:01:49 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 1106 invoked by uid 22791); 7 Jul 2009 18:01:45 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org To: gdb-patches@sourceware.org Cc: ppluzhnikov@google.com, archer@sourceware.org Subject: [patch] fix for crash in python pretty-printer Message-Id: <20090707180121.D6ECE76BC0@localhost> Date: Tue, 07 Jul 2009 18:01:00 -0000 From: ppluzhnikov@google.com (Paul Pluzhnikov) X-SW-Source: 2009-q3/txt/msg00025.txt.bz2 Greetings, This is rather on the obvious side. While debugging a buggy pretty-printer, GDB crashed on me: Program received signal SIGSEGV, Segmentation fault. 0x000000000045db13 in do_my_cleanups (pmy_chain=0xa7c020, old_chain=0x1e65a10) at ../../gdb/utils.c:390 390 *pmy_chain = ptr->next; /* Do this first incase recursion */ ptr is NULL at that point. (top) bt #0 0x000000000045db13 in do_my_cleanups (pmy_chain=0xa7c020, old_chain=0x1e65a10) at ../../gdb/utils.c:390 #1 0x000000000045dadf in do_cleanups (...) at ../../gdb/utils.c:374 #2 0x00000000004d684b in apply_val_pretty_printer (...) at ../../gdb/python/python-prettyprint.c:526 #3 0x000000000051286a in value_print (...) at ../../gdb/valprint.c:388 #4 0x0000000000514f53 in print_formatted (...) at ../../gdb/printcmd.c:316 ... Attached is a fix (applies both to mainline and archer-tromey-python). Tested on Linux/x86_64 with no regressions. P.S. Is there an "easy" way to find such mis-uses of TRY_CATCH? This one took me 2 hours to find :-( Thanks, -- Paul Pluzhnikov 2009-07-07 Paul Pluzhnikov * python/python-value.c (valpy_getitem): Don't return from TRY_CATCH. diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c index 8c85ef6..489b65b 100644 --- a/gdb/python/python-value.c +++ b/gdb/python/python-value.c @@ -290,8 +290,7 @@ valpy_getitem (PyObject *self, PyObject *key) { value_object *self_value = (value_object *) self; char *field = NULL; - struct value *idx = NULL; - struct value *res_val = NULL; /* Initialize to appease gcc warning. */ + struct value *res_val = NULL; volatile struct gdb_exception except; if (gdbpy_is_string (key)) @@ -313,12 +312,17 @@ valpy_getitem (PyObject *self, PyObject *key) value code throw an exception if the index has an invalid type. */ struct value *idx = convert_value_from_python (key); - if (idx == NULL) - return NULL; - - res_val = value_subscript (tmp, value_as_long (idx)); + if (idx != NULL) + res_val = value_subscript (tmp, value_as_long (idx)); } } + + if (res_val == NULL) + { + gdb_assert (field == NULL); + return NULL; + } + if (field) xfree (field); GDB_PY_HANDLE_EXCEPTION (except);