This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Fix nullptr in with_command_1
- From: Pedro Alves <palves at redhat dot com>
- To: Tom Tromey <tom at tromey dot com>, Bogdan Harjoc <harjoc at gmail dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 21 Aug 2019 21:14:39 +0100
- Subject: Re: [PATCH] Fix nullptr in with_command_1
- References: <CAF4+tmqL0NH6mPufUF0y7+-+7=_OC7FXhDOHE+fVC6=RiFa=RQ@mail.gmail.com> <87y30be94z.fsf@tromey.com>
On 8/2/19 7:04 PM, Tom Tromey wrote:
>>>>>> "Bogdan" == Bogdan Harjoc <harjoc@gmail.com> writes:
>
> Bogdan> Reproduced with gdb built from git HEAD, running 'with' without
> Bogdan> arguments. Patch is attached.
>
> This needs a ChangeLog entry.
> I think a simple test case would also be good.
>
Ah, I could swear that I had tested this... Obviously not.
I've added a test, ChangeLog entries, and merged it.
Thanks for noticing/fixing this!
>From 26c957f12762816a90d5145c7c527ca48c890855 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Wed, 21 Aug 2019 21:11:33 +0100
Subject: [PATCH] Fix nullptr in with_command_1
Running 'with' without arguments crashes GDB. This fixes it.
gdb/ChangeLog:
2019-08-21 Bogdan Harjoc <harjoc@gmail.com>
* cli/cli-cmds.c (with_command_1): Error out if no arguments.
gdb/testsuite/ChangeLog:
2019-08-21 Pedro Alves <palves@redhat.com>
* gdb.base/with.exp: Test "with" with no arguments.
---
gdb/ChangeLog | 4 ++++
gdb/testsuite/ChangeLog | 4 ++++
gdb/cli/cli-cmds.c | 3 +++
gdb/testsuite/gdb.base/with.exp | 2 ++
4 files changed, 13 insertions(+)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 01e60fb1894..966bfb7d9fc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2019-08-21 Bogdan Harjoc <harjoc@gmail.com>
+
+ * cli/cli-cmds.c (with_command_1): Error out if no arguments.
+
2019-08-21 Christian Biesinger <cbiesinger@google.com>
* tui/tui-data.h (tui_gen_win_info): Add an =default
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 7fea9cd0712..e56cc16628d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2019-08-21 Pedro Alves <palves@redhat.com>
+
+ * gdb.base/with.exp: Test "with" with no arguments.
+
2019-08-21 Tom de Vries <tdevries@suse.de>
* gdb.base/gdb-caching-proc.exp: Sort files.
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 30e0958b60b..4fc656775c9 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -217,6 +217,9 @@ void
with_command_1 (const char *set_cmd_prefix,
cmd_list_element *setlist, const char *args, int from_tty)
{
+ if (args == nullptr)
+ error (_("Missing arguments."));
+
const char *delim = strstr (args, "--");
const char *nested_cmd = nullptr;
diff --git a/gdb/testsuite/gdb.base/with.exp b/gdb/testsuite/gdb.base/with.exp
index 9ea768563a3..a972296d78f 100644
--- a/gdb/testsuite/gdb.base/with.exp
+++ b/gdb/testsuite/gdb.base/with.exp
@@ -220,6 +220,8 @@ with_test_prefix "run control" {
# Check errors.
with_test_prefix "errors" {
+ gdb_test "with" "Missing arguments\\."
+
# Try both an unknown root setting and an unknown prefixed
# setting. The errors come from different locations in the
# sources.
--
2.14.5