This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Check for negative argument in Type.template_argument


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fd3ba736db19d4c7cd928f3735329339a8c8ef47

commit fd3ba736db19d4c7cd928f3735329339a8c8ef47
Author: Tom Tromey <tom@tromey.com>
Date:   Sat Sep 15 00:29:20 2018 -0600

    Check for negative argument in Type.template_argument
    
    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.

Diff:
---
 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/ChangeLog b/gdb/ChangeLog
index 15ae55a..f887159 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 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:
 	* python/python.c (gdbpy_run_events): Do not ignore exceptions.
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index c7cad2e..897ad93 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/ChangeLog b/gdb/testsuite/ChangeLog
index 131940b..4a624dd 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,11 @@
 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:
 	* gdb.python/python.exp: Add test for post_event error.
 
diff --git a/gdb/testsuite/gdb.python/py-template.exp b/gdb/testsuite/gdb.python/py-template.exp
index 793e68d..96383a7 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"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]