bug 23124: rust - Fix null deref when casting

Message ID 20180428032443.GA1869@tomyris
State New, archived
Headers

Commit Message

Dan Robertson April 28, 2018, 3:24 a.m. UTC
  Attached a patch that fixes bug 23124.

Cheers,

Dan
  

Comments

Tom Tromey April 29, 2018, 3:49 a.m. UTC | #1
>>>>> "Dan" == Dan Robertson <danlrobertson89@gmail.com> writes:

Dan> Attached a patch that fixes bug 23124.

Thanks for the patch.

This is the right fix, but there are a few nits.  If you want to address
those, that would be nice.  If you can't, I will do it on Monday.

It is missing a ChangeLog entry.  It's normal to mention the bug in the
ChangeLog, see any of the ones mentioning "PR .../NNNN".

It needs a test, feel free to just drop the simplest thing possible into
gdb/testsuite/gdb.rust/expr.exp.  The test suite, for some reason, has a
ChangeLog of its own.

Dan> -  for (const rust_op *op : *params)
Dan> -    result.push_back (convert_ast_to_type (state, op));
Dan> +  if (params) {
Dan> +    for (const rust_op *op : *params) {
Dan> +      result.push_back (convert_ast_to_type (state, op));
Dan> +    }
Dan> +  }

In the gdb flavor of GNU style, one would format this as:

if (params != nullptr)
  {
    for (const rust_op *op : *params)
      result.push_back (convert_ast_to_type (state, op));
  }

Tom
  

Patch

From 7ebef0f7305cfe9bc56bf658dc889abf2da4ee02 Mon Sep 17 00:00:00 2001
From: Dan Robertson <danlrobertson89@gmail.com>
Date: Sat, 28 Apr 2018 03:18:00 +0000
Subject: [PATCH] bug 23124: rust - Fix null deref when casting

Fix a null dereference when casting a value to a unit type.
---
 gdb/rust-exp.y | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index b661a803e3..4be01b0719 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -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) {
+    for (const rust_op *op : *params) {
+      result.push_back (convert_ast_to_type (state, op));
+    }
+  }
 
   return result;
 }
-- 
2.17.0