From patchwork Thu Nov 3 22:54:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17173 Received: (qmail 123500 invoked by alias); 3 Nov 2016 22:54:53 -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 123483 invoked by uid 89); 3 Nov 2016 22:54:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=ugly, H*r:4.86_1, H*F:U*tom, H*RU:cmgw2 X-HELO: gproxy9-pub.mail.unifiedlayer.com Received: from gproxy9-pub.mail.unifiedlayer.com (HELO gproxy9-pub.mail.unifiedlayer.com) (69.89.20.122) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Thu, 03 Nov 2016 22:54:43 +0000 Received: (qmail 6368 invoked by uid 0); 3 Nov 2016 22:54:41 -0000 Received: from unknown (HELO cmgw2) (10.0.90.83) by gproxy9.mail.unifiedlayer.com with SMTP; 3 Nov 2016 22:54:41 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 3auc1u00j2f2jeq01aufsX; Thu, 03 Nov 2016 16:54:40 -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=L24OOQBejmoA:10 a=zstS-IiYAAAA:8 a=KKAkSRfTAAAA:8 a=20KFwNOVAAAA:8 a=CMAFOjKEq5ubX2B2HtoA:9 a=nCR9vBEB-81GE7lh:21 a=jfFaiFe-DUKQvSgK:21 a=4G6NA9xxw8l3yy4pmD5M:22 a=cvBusfyB2V15izCimMoJ:22 a=e_O65bzb51kRm2y5VmPK:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:56264 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c2Qu6-00051k-DK; Thu, 03 Nov 2016 16:54:38 -0600 From: Tom Tromey To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA 1/2] Fix some error-handling bugs in python frame filters References: <1477951905-14880-1-git-send-email-tom@tromey.com> <1477951905-14880-2-git-send-email-tom@tromey.com> Date: Thu, 03 Nov 2016 16:54:37 -0600 In-Reply-To: <1477951905-14880-2-git-send-email-tom@tromey.com> (Tom Tromey's message of "Mon, 31 Oct 2016 16:11:44 -0600") Message-ID: <87y4105g42.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) MIME-Version: 1.0 X-BWhitelist: no X-Exim-ID: 1c2Qu6-00051k-DK X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya) [174.16.143.211]:56264 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== >>>>> "Tom" == Tom Tromey writes: Tom> I've included a test case for the first issue. I did a -m32 build here and have fixed up the test case. Here's the new patch. This is ready to review now. Tom commit 981628a4af5f82a12351b9764437927d3a8c8169 Author: Tom Tromey Date: Mon Oct 31 11:10:35 2016 -0600 Fix some error-handling bugs in python frame filters 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. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1fd85ce..98fcd21 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-11-03 Yao Qi * Makefile.in (.y.c): Replace YY_NULL with YY_NULLPTR. 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..2580911 100644 --- a/gdb/testsuite/gdb.python/py-framefilter.py +++ b/gdb/testsuite/gdb.python/py-framefilter.py @@ -92,6 +92,12 @@ class ElidingFrameDecorator(FrameDecorator): def elided(self): return iter(self.elided_frames) + def address (self): + # Regression test for an overflow in the python layer. + bitsize = 8 * gdb.lookup_type('void').pointer().sizeof + mask = (1 << bitsize) - 1 + return 0xffffffffffffffff & mask + class ElidingIterator: def __init__(self, ii): self.input_iterator = ii