Check for negative argument in Type.template_argument
authorTom Tromey <tom@tromey.com>
Sat, 15 Sep 2018 06:29:20 +0000 (00:29 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 24 Sep 2018 05:15:12 +0000 (23:15 -0600)
typy_template_argument did not check if the template argument was
non-negative.  A negative value could cause a gdb crash.

2018-09-23  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-23  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
gdb/python/py-type.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-template.exp

index 15ae55a18417040f62bc2da6cef2106217b96037..f887159d221ee15ee88f42b2b1c5a417433cd350 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-23  Tom Tromey  <tom@tromey.com>
+
+       PR python/17284:
+       * python/py-type.c (typy_template_argument): Check for negative
+       argument number.
+
 2018-09-23  Tom Tromey  <tom@tromey.com>
 
        PR python/14062:
index c7cad2e66288c0d22244687066919db386475182..897ad9374af569cead30c9ffe3cf67b52ee13efc 100644 (file)
@@ -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);
index 131940bc184a9efa1bcf6d8fffe3937599328146..4a624ddd662310e560151e2fcbcea98352ecc0cf 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-23  Tom Tromey  <tom@tromey.com>
+
+       PR python/17284:
+       * gdb.python/py-template.exp (test_template_arg): Add test for
+       negative template argument number.
+
 2018-09-23  Tom Tromey  <tom@tromey.com>
 
        PR python/14062:
index 793e68d7fe447856e63b44ce02450cdd946e2af6..96383a73c517b2096260a4927fbb9c1c35291870 100644 (file)
@@ -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"
This page took 0.066425 seconds and 4 git commands to generate.