From patchwork Sat Sep 15 07:24:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29386 Received: (qmail 29633 invoked by alias); 15 Sep 2018 07:25:20 -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 29462 invoked by uid 89); 15 Sep 2018 07:25:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.145.4) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Sep 2018 07:25:05 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 7CE78A2672 for ; Sat, 15 Sep 2018 02:25:04 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 14wygpSod79N314wyg0fh6; Sat, 15 Sep 2018 02:25:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=4F8+lYdK1YiuL8JtThFw8lF59z5fZPGiB7aIAY6ShM0=; b=ibupBU4Jjv/9+H/wc1ZLbk/U96 wvHoRM+piqhFZbq8WJ+CeWRPk0iCj3llfPn4e6aca/lQXMeX1sIaXZ8b4eEInA3TZuy2DE+SuGsKZ BN44eV4w7Gm4aZoSqFa5kqDiW; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:41846 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g14wy-00253W-9j; Sat, 15 Sep 2018 02:25:04 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 5/7] Check for negative argument in Type.template_argument Date: Sat, 15 Sep 2018 01:24:57 -0600 Message-Id: <20180915072459.14934-6-tom@tromey.com> In-Reply-To: <20180915072459.14934-1-tom@tromey.com> References: <20180915072459.14934-1-tom@tromey.com> typy_template_argument did not check if the template argument was non-negative. A negative value could cause a gdb crash. gdb/ChangeLog 2018-09-15 Tom Tromey PR python/17284: * python/py-type.c (typy_template_argument): Check for negative argument number. gdb/testsuite/ChangeLog 2018-09-15 Tom Tromey PR python/17284: * gdb.python/py-template.exp (test_template_arg): Add test for negative template argument number. --- gdb/ChangeLog | 6 ++++++ gdb/python/py-type.c | 7 +++++++ gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.python/py-template.exp | 4 ++++ 4 files changed, 23 insertions(+) diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index c7cad2e6628..897ad9374af 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -930,6 +930,13 @@ typy_template_argument (PyObject *self, PyObject *args) if (! PyArg_ParseTuple (args, "i|O", &argno, &block_obj)) return NULL; + if (argno < 0) + { + PyErr_SetString (PyExc_RuntimeError, + _("Template argument number must be non-negative")); + return NULL; + } + if (block_obj) { block = block_object_to_block (block_obj); diff --git a/gdb/testsuite/gdb.python/py-template.exp b/gdb/testsuite/gdb.python/py-template.exp index 793e68d7fe4..96383a73c51 100644 --- a/gdb/testsuite/gdb.python/py-template.exp +++ b/gdb/testsuite/gdb.python/py-template.exp @@ -54,6 +54,10 @@ proc test_template_arg {exefile type} { # Replace '*' with '\*' in regex. regsub -all {\*} $type {\*} t gdb_test "python print (foo.type.template_argument(0))" $t $type + + gdb_test "python print(foo.type.template_argument(-1))" \ + "Template argument number must be non-negative\r\nError while executing Python code." \ + "negative template argument number" } test_template_arg "${binfile}-ci" "const int"