Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: ppluzhnikov@google.com (Paul Pluzhnikov)
To: gdb-patches@sourceware.org
Cc: ppluzhnikov@google.com, archer@sourceware.org
Subject: [patch] fix for crash in python pretty-printer
Date: Tue, 07 Jul 2009 18:01:00 -0000	[thread overview]
Message-ID: <20090707180121.D6ECE76BC0@localhost> (raw)

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  <ppluzhnikov@google.com>

	* 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);


             reply	other threads:[~2009-07-07 18:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-07 18:01 Paul Pluzhnikov [this message]
2009-07-07 18:23 ` Tom Tromey
2009-07-07 19:51   ` Paul Pluzhnikov
2009-07-07 20:41     ` Paul Pluzhnikov
2009-07-07 20:54       ` Tom Tromey
2009-07-07 21:05         ` Paul Pluzhnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090707180121.D6ECE76BC0@localhost \
    --to=ppluzhnikov@google.com \
    --cc=archer@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox