Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] bug 23124: rust - Fix null deref when casting
@ 2018-04-28  3:27 Dan Robertson
  2018-04-29  3:49 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Robertson @ 2018-04-28  3:27 UTC (permalink / raw)
  To: gdb-patches


[-- Attachment #1.1: Type: text/plain, Size: 53 bytes --]

Attached a patch that fixes bug 23124.

Cheers,

Dan

[-- Attachment #1.2: 0001-bug-23124-rust-Fix-null-deref-when-casting.patch --]
[-- Type: text/x-diff, Size: 918 bytes --]

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


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bug 23124: rust - Fix null deref when casting
  2018-04-28  3:27 [PATCH] bug 23124: rust - Fix null deref when casting Dan Robertson
@ 2018-04-29  3:49 ` Tom Tromey
  2018-04-29 16:18   ` Dan Robertson
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2018-04-29  3:49 UTC (permalink / raw)
  To: Dan Robertson; +Cc: gdb-patches

>>>>> "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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bug 23124: rust - Fix null deref when casting
  2018-04-29  3:49 ` Tom Tromey
@ 2018-04-29 16:18   ` Dan Robertson
  2018-05-01  5:09     ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Robertson @ 2018-04-29 16:18 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches


[-- Attachment #1.1: Type: text/plain, Size: 262 bytes --]

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

[-- Attachment #1.2: 0001-rust-Fix-null-deref-when-casting-PR-23124.patch --]
[-- Type: text/x-diff, Size: 2700 bytes --]

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(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index cd86be7fb3..102d54b442 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-26  Andrzej Kaczmarek  <andrzej.kaczmarek@codecoup.pl>
 
 	PR remote/9665
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index b661a803e3..865959f7d9 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 != 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 34da102c62..c52fa15335 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-26  Pedro Alves  <palves@redhat.com>
 
 	* gdb.base/gnu-ifunc.exp (set-break): Test that GDB resolves
diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp
index 0bc0630854..22e6b49b54 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"
-- 
2.17.0


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bug 23124: rust - Fix null deref when casting
  2018-04-29 16:18   ` Dan Robertson
@ 2018-05-01  5:09     ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2018-05-01  5:09 UTC (permalink / raw)
  To: Dan Robertson; +Cc: Tom Tromey, gdb-patches

>>>>> "Dan" == Dan Robertson <danlrobertson89@gmail.com> writes:

Dan> Thanks for the critiques! Attached an updated patch.  Added the minimal
Dan> repro listed in the bug and a simple function pointer example to
Dan> gdb.rust/expr.exp. I also added ChangeLog entries and updated the change to
Dan> align with the gdb code standards.

Thanks once again.  I'm pushing this now.
I slightly reformatted the ChangeLog since one line was too long.

Tom


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-01  5:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-28  3:27 [PATCH] bug 23124: rust - Fix null deref when casting Dan Robertson
2018-04-29  3:49 ` Tom Tromey
2018-04-29 16:18   ` Dan Robertson
2018-05-01  5:09     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox