PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash

Message ID 20170215201548.29225-1-sergiodj@redhat.com
State New, archived
Headers

Commit Message

Sergio Durigan Junior Feb. 15, 2017, 8:15 p.m. UTC
  Hi,

This is a fix for PR gdb/21164.  The problem started to happen after:

 commit 34c41c681f4a0a0dfe0405c7d2aecf458520557a
 Author:     Doug Evans <xdje42@gmail.com>
 AuthorDate: Mon Dec 19 08:33:46 2016 -0800

    New syntax for mt print symbols,msymbols,psymbols.

This change introduced new syntax for the mentioned commands, and
improved the parsing of arguments by using 'gdb_buildargv'.  However,
it is necessary to check if the argv being built is not NULL, which
can happen if the user doesn't provide any arguments to these
commands.

This patch fixes that.  OK to apply?

gdb/ChangeLog:
2017-02-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR gdb/21164
	* psymtab.c (maintenance_print_psymbols): Verify if 'argv' is not
	NULL before using it.
	* symmisc.c (maintenance_print_symbols): Likewise.
	(maintenance_print_msymbols): Likewise.
---
 gdb/psymtab.c | 4 ++--
 gdb/symmisc.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
  

Comments

Pedro Alves Feb. 15, 2017, 10:12 p.m. UTC | #1
On 02/15/2017 08:15 PM, Sergio Durigan Junior wrote:

> This patch fixes that.  OK to apply?

Can you add some tests for this, please?

Thanks,
Pedro Alves
  
Sergio Durigan Junior Feb. 15, 2017, 10:48 p.m. UTC | #2
On Wednesday, February 15 2017, Pedro Alves wrote:

> On 02/15/2017 08:15 PM, Sergio Durigan Junior wrote:
>
>> This patch fixes that.  OK to apply?
>
> Can you add some tests for this, please?

Sure.  I should have added them from the beginning, sorry.
  

Patch

diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 1fad8a0..6e42bc5 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1926,7 +1926,7 @@  maintenance_print_psymbols (char *args, int from_tty)
   argv = gdb_buildargv (args);
   cleanups = make_cleanup_freeargv (argv);
 
-  for (i = 0; argv[i] != NULL; ++i)
+  for (i = 0; argv != NULL && argv[i] != NULL; ++i)
     {
       if (strcmp (argv[i], "-pc") == 0)
 	{
@@ -1967,7 +1967,7 @@  maintenance_print_psymbols (char *args, int from_tty)
 
   stdio_file arg_outfile;
 
-  if (argv[outfile_idx] != NULL)
+  if (argv != NULL && argv[outfile_idx] != NULL)
     {
       char *outfile_name;
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 07d571a..ab50570 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -418,7 +418,7 @@  maintenance_print_symbols (char *args, int from_tty)
   argv = gdb_buildargv (args);
   cleanups = make_cleanup_freeargv (argv);
 
-  for (i = 0; argv[i] != NULL; ++i)
+  for (i = 0; argv != NULL && argv[i] != NULL; ++i)
     {
       if (strcmp (argv[i], "-pc") == 0)
 	{
@@ -459,7 +459,7 @@  maintenance_print_symbols (char *args, int from_tty)
 
   stdio_file arg_outfile;
 
-  if (argv[outfile_idx] != NULL)
+  if (argv != NULL && argv[outfile_idx] != NULL)
     {
       char *outfile_name;
 
@@ -721,7 +721,7 @@  maintenance_print_msymbols (char *args, int from_tty)
   argv = gdb_buildargv (args);
   cleanups = make_cleanup_freeargv (argv);
 
-  for (i = 0; argv[i] != NULL; ++i)
+  for (i = 0; argv != NULL && argv[i] != NULL; ++i)
     {
       if (strcmp (argv[i], "-objfile") == 0)
 	{
@@ -747,7 +747,7 @@  maintenance_print_msymbols (char *args, int from_tty)
 
   stdio_file arg_outfile;
 
-  if (argv[outfile_idx] != NULL)
+  if (argv != NULL && argv[outfile_idx] != NULL)
     {
       char *outfile_name;