From patchwork Mon Oct 31 22:11:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17047 Received: (qmail 122446 invoked by alias); 31 Oct 2016 22:14:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 122427 invoked by uid 89); 31 Oct 2016 22:14:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=UD:python, tom@tromey.com, U*tom, D*tromey.com X-HELO: gproxy1.mail.unifiedlayer.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO gproxy1.mail.unifiedlayer.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 31 Oct 2016 22:13:51 +0000 Received: from cmgw2 (cmgw3 [10.0.90.83]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 77CA1176E1F for ; Mon, 31 Oct 2016 16:12:11 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 2NBn1u00U2f2jeq01NBqMJ; Mon, 31 Oct 2016 16:11:50 -0600 X-Authority-Analysis: v=2.1 cv=PIacp5aC c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=CH0kA5CcgfcA:10 a=zstS-IiYAAAA:8 a=r_1tXGB3AAAA:8 a=20KFwNOVAAAA:8 a=UuRhk1ZPPy6Q1Sc9PDYA:9 a=uwTOWvHjA1wSsnUe:21 a=_U-IcUmurlH1Uhml:21 a=4G6NA9xxw8l3yy4pmD5M:22 a=t8nPyN_e6usw4ciXM-Pk:22 a=e_O65bzb51kRm2y5VmPK:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:52914 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c1Ko0-0003Vl-M0; Mon, 31 Oct 2016 16:11:48 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 1/2] Fix some error-handling bugs in python frame filters Date: Mon, 31 Oct 2016 16:11:44 -0600 Message-Id: <1477951905-14880-2-git-send-email-tom@tromey.com> In-Reply-To: <1477951905-14880-1-git-send-email-tom@tromey.com> References: <1477951905-14880-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c1Ko0-0003Vl-M0 X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya.Home) [174.16.143.211]:52914 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== While writing a Python frame filter, I found a few bugs in the current frame filter code. In particular: * One spot converts a Python long to a CORE_ADDR using PyLong_AsLong. However, this can fail on overflow. I changed this to use get_addr_from_python. * Another spot is doing the same but with PyLong_AsUnsignedLongLong; I changed this as well just for consistency. * Converting line numbers can print "-1" if conversion from long fails. This isn't fatal but just a bit ugly. I've included a test case for the first issue. The line number one didn't seem important enough to bother with. 2016-10-31 Tom Tromey * python/py-framefilter.c (py_print_frame): Use get_addr_from_python. Check for errors when getting line number. 2016-10-31 Tom Tromey * gdb.python/py-framefilter.py (ElidingFrameDecorator.address): New method. --- gdb/ChangeLog | 5 +++++ gdb/python/py-framefilter.c | 18 +++++++++++++++--- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.python/py-framefilter.py | 4 ++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f917305..f549e88 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2016-10-31 Tom Tromey + + * python/py-framefilter.c (py_print_frame): Use + get_addr_from_python. Check for errors when getting line number. + 2016-10-31 Maciej W. Rozycki * mips-tdep.c (mips_r3041_reg_names): Remove. diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index 6692ac5..4c7757c 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -1116,7 +1116,13 @@ py_print_frame (PyObject *filter, int flags, if (paddr != Py_None) { - address = PyLong_AsLong (paddr); + if (get_addr_from_python (paddr, &address) < 0) + { + Py_DECREF (paddr); + do_cleanups (cleanup_stack); + return EXT_LANG_BT_ERROR; + } + has_addr = 1; } Py_DECREF (paddr); @@ -1213,10 +1219,10 @@ py_print_frame (PyObject *filter, int flags, } else if (PyLong_Check (py_func)) { - CORE_ADDR addr = PyLong_AsUnsignedLongLong (py_func); + CORE_ADDR addr; struct bound_minimal_symbol msymbol; - if (PyErr_Occurred ()) + if (get_addr_from_python (py_func, &addr) < 0) { do_cleanups (cleanup_stack); return EXT_LANG_BT_ERROR; @@ -1340,6 +1346,12 @@ py_print_frame (PyObject *filter, int flags, if (py_line != Py_None) { line = PyLong_AsLong (py_line); + if (PyErr_Occurred ()) + { + do_cleanups (cleanup_stack); + return EXT_LANG_BT_ERROR; + } + TRY { ui_out_text (out, ":"); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 52038e3..d8466f1 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-10-31 Tom Tromey + + * gdb.python/py-framefilter.py (ElidingFrameDecorator.address): + New method. + 2016-10-28 Pedro Alves * gdb.base/maint.exp : Use diff --git a/gdb/testsuite/gdb.python/py-framefilter.py b/gdb/testsuite/gdb.python/py-framefilter.py index 8fdff84..3acd26e 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.py +++ b/gdb/testsuite/gdb.python/py-framefilter.py @@ -92,6 +92,10 @@ class ElidingFrameDecorator(FrameDecorator): def elided(self): return iter(self.elided_frames) + def address (self): + # Regression test for an overflow in the python layer. + return 0xffffffffffffffff + class ElidingIterator: def __init__(self, ii): self.input_iterator = ii