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] rust: Fix null deref when casting (PR 23124)


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

commit 1632f8baf04e7351f387e58957fc04498d90987d
Author: Dan Robertson <danlrobertson89@gmail.com>
Date:   Sat Apr 28 03:18:00 2018 +0000

    rust: Fix null deref when casting (PR 23124)
    
    Fix a null dereference when casting a value to a unit type.
    
    ChangeLog
    2018-04-28  Dan Robertson  <danlrobertson89@gmail.com>
    
    	PR rust/23124
    	* gdb/rust-exp.y (convert_params_to_types): Ensure that the params
    	pointer is not null before dereferencing it.
    
    testsuite/ChangeLog
    2018-04-28  Dan Robertson  <danlrobertson89@gmail.com>
    
    	PR rust/23124
    	* gdb.rust/expr.exp: Test that the unit type is correctly parsed
    	when casting.

Diff:
---
 gdb/ChangeLog                   | 6 ++++++
 gdb/rust-exp.y                  | 7 +++++--
 gdb/testsuite/ChangeLog         | 6 ++++++
 gdb/testsuite/gdb.rust/expr.exp | 4 +++-
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9c2264b..85f7525 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2018-04-28  Dan Robertson  <danlrobertson89@gmail.com>
+
+	PR rust/23124
+	* gdb/rust-exp.y (convert_params_to_types): Ensure that the params
+	pointer is not null before dereferencing it.
+
 2018-04-30  Tom Tromey  <tom@tromey.com>
 
 	* darwin-nat-info.c (darwin_debug_regions_recurse): Remove use of
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 56aa689..9f21498 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -2019,8 +2019,11 @@ convert_params_to_types (struct parser_state *state, rust_op_vector *params)
 {
   std::vector<struct type *> result;
 
-  for (const rust_op *op : *params)
-    result.push_back (convert_ast_to_type (state, op));
+  if (params != nullptr)
+    {
+      for (const rust_op *op : *params)
+        result.push_back (convert_ast_to_type (state, op));
+    }
 
   return result;
 }
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 4e48934..cb5e6d0 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-04-28  Dan Robertson  <danlrobertson89@gmail.com>
+
+	PR rust/23124
+	* gdb.rust/expr.exp: Test that the unit type is correctly parsed
+	when casting.
+
 2018-04-30  Tom Tromey  <tom@tromey.com>
 
 	* gdb.python/py-type.exp: Check align attribute.
diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp
index 0bc0630..22e6b49 100644
--- a/gdb/testsuite/gdb.rust/expr.exp
+++ b/gdb/testsuite/gdb.rust/expr.exp
@@ -133,7 +133,9 @@ gdb_test "print \[23usize; 4\]" " = \\\[23, 23, 23, 23\\\]"
 gdb_test "ptype \[23usize; 4\]" " = \\\[usize; 4\\\]"
 gdb_test "print \[mut 23usize; 4\]" " = \\\[23, 23, 23, 23\\\]"
 
-# Test a lexer corner case.
+# Test lexer corner cases.
+gdb_test "print 0x0 as *const ()" " = \\\(\\\(\\\) \\*\\\) 0x0"
+gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\\(\\\) \\\(\\*\\\)\\\(i64\\\)\\\) 0x0"
 gdb_test "print r#" "syntax error in expression, near `#'\\."
 
 gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22"


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