Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 5/7] Check for negative argument in Type.template_argument
Date: Sat, 15 Sep 2018 07:25:00 -0000	[thread overview]
Message-ID: <20180915072459.14934-6-tom@tromey.com> (raw)
In-Reply-To: <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  <tom@tromey.com>

	PR python/17284:
	* python/py-type.c (typy_template_argument): Check for negative
	argument number.

gdb/testsuite/ChangeLog
2018-09-15  Tom Tromey  <tom@tromey.com>

	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"
-- 
2.17.1


      parent reply	other threads:[~2018-09-15  7:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-15  7:25 [PATCH 0/7] some small python fixes (one including a doc patch) Tom Tromey
2018-09-15  7:25 ` [PATCH 4/7] Report Python errors coming from gdb.post_event Tom Tromey
2018-09-15  7:25 ` [PATCH 7/7] Allow setting a parameter to raise gdb.GdbError Tom Tromey
2018-09-15  9:16   ` Eli Zaretskii
2018-09-24  2:39     ` Simon Marchi
2018-09-24  4:58       ` Tom Tromey
2018-09-24  5:14         ` Tom Tromey
2018-09-24  7:10       ` Eli Zaretskii
2018-09-24 10:24         ` Tom Tromey
2018-09-24 12:39           ` Eli Zaretskii
2018-09-15  7:25 ` [PATCH 2/7] Preserve sign when converting gdb.Value to Python int Tom Tromey
2018-09-15  7:25 ` [PATCH 1/7] Allow more Python scalar conversions Tom Tromey
2018-09-24  2:06   ` Simon Marchi
2018-09-24  4:58     ` Tom Tromey
2018-09-15  7:25 ` [PATCH 3/7] Allow conversion of pointers to Python int Tom Tromey
2018-09-15  7:25 ` [PATCH 6/7] Consolidate gdb.GdbError handling Tom Tromey
2018-09-15  7:25 ` Tom Tromey [this message]

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=20180915072459.14934-6-tom@tromey.com \
    --to=tom@tromey.com \
    --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