bug 23124: rust - Fix null deref when casting
Commit Message
Thanks for the critiques! Attached an updated patch. Added the minimal
repro listed in the bug and a simple function pointer example to
gdb.rust/expr.exp. I also added ChangeLog entries and updated the change to
align with the gdb code standards.
Cheers,
Dan
From e20401ca99c82ac4b0cf39e87b4771388360a211 Mon Sep 17 00:00:00 2001
From: Dan Robertson <danlrobertson89@gmail.com>
Date: Sat, 28 Apr 2018 03:18:00 +0000
Subject: [PATCH] rust: Fix null deref when casting (PR 23124)
Fix a null dereference when casting a value to a unit type.
---
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(-)
@@ -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-26 Andrzej Kaczmarek <andrzej.kaczmarek@codecoup.pl>
PR remote/9665
@@ -2007,8 +2007,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;
}
@@ -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-26 Pedro Alves <palves@redhat.com>
* gdb.base/gnu-ifunc.exp (set-break): Test that GDB resolves
@@ -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"
--
2.17.0