public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash
@ 2017-02-15 20:16 Sergio Durigan Junior
  2017-02-15 22:12 ` Pedro Alves
  0 siblings, 1 reply; 6+ messages in thread
From: Sergio Durigan Junior @ 2017-02-15 20:16 UTC (permalink / raw)
  To: GDB Patches; +Cc: Doug Evans, Sergio Durigan Junior

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

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;
 
-- 
2.9.3

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

* Re: [PATCH] PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash
  2017-02-15 20:16 [PATCH] PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash Sergio Durigan Junior
@ 2017-02-15 22:12 ` Pedro Alves
  2017-02-15 22:48   ` Sergio Durigan Junior
  2017-02-15 22:54   ` Sergio Durigan Junior
  0 siblings, 2 replies; 6+ messages in thread
From: Pedro Alves @ 2017-02-15 22:12 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches; +Cc: Doug Evans

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

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

* Re: [PATCH] PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash
  2017-02-15 22:12 ` Pedro Alves
@ 2017-02-15 22:48   ` Sergio Durigan Junior
  2017-02-15 22:54   ` Sergio Durigan Junior
  1 sibling, 0 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2017-02-15 22:48 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Doug Evans

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.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

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

* Re: [PATCH] PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash
  2017-02-15 22:12 ` Pedro Alves
  2017-02-15 22:48   ` Sergio Durigan Junior
@ 2017-02-15 22:54   ` Sergio Durigan Junior
  2017-02-15 23:06     ` Pedro Alves
  1 sibling, 1 reply; 6+ messages in thread
From: Sergio Durigan Junior @ 2017-02-15 22:54 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Doug Evans

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?

How about this?

Thanks

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

commit acd6597d63b2501588318466cd308701d09a58f3
Author: Sergio Durigan Junior <sergiodj@redhat.com>
Date:   Wed Feb 15 15:08:19 2017 -0500

    PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash
    
    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/testsuite/ChangeLog:
    
    gdb/ChangeLog:
    2017-02-15  Sergio Durigan Junior  <sergiodj@redhat.com>
    
            PR gdb/21164
            * gdb.base/maint.exp: Add testcases for when the commands do
            not have arguments.

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;
 
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index 2853508..b87cbfc 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -561,6 +561,14 @@ gdb_expect {
 
 #set timeout $oldtimeout
 
+# Testing that the commands work without an argument.  For this test,
+# we don't need an inferior loaded/running.
+# See PR gdb/21164.
+gdb_exit
+gdb_start
+gdb_test_no_output "maint print symbols"
+gdb_test_no_output "maint print msymbols"
+gdb_test_no_output "maint print psymbols"
 
 gdb_exit
 return 0

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

* Re: [PATCH] PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash
  2017-02-15 22:54   ` Sergio Durigan Junior
@ 2017-02-15 23:06     ` Pedro Alves
  2017-02-16  0:57       ` Sergio Durigan Junior
  0 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2017-02-15 23:06 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches, Doug Evans

On 02/15/2017 10:54 PM, Sergio Durigan Junior wrote:
> 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?
> 
> How about this?

Awesome, thanks!  OK with minor nits.

> commit acd6597d63b2501588318466cd308701d09a58f3
> Author: Sergio Durigan Junior <sergiodj@redhat.com>
> Date:   Wed Feb 15 15:08:19 2017 -0500

>     Hi,

...remove this above...

>     This patch fixes that.  OK to apply?

...and this "OK" from the commit log and...

> diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
> index 2853508..b87cbfc 100644
> --- a/gdb/testsuite/gdb.base/maint.exp
> +++ b/gdb/testsuite/gdb.base/maint.exp
> @@ -561,6 +561,14 @@ gdb_expect {
>  
>  #set timeout $oldtimeout
>  
> +# Testing that the commands work without an argument.  For this test,

Write "Test that" here.

> +# we don't need an inferior loaded/running.
> +# See PR gdb/21164.
> +gdb_exit
> +gdb_start
> +gdb_test_no_output "maint print symbols"
> +gdb_test_no_output "maint print msymbols"
> +gdb_test_no_output "maint print psymbols"

Thanks,
Pedro Alves

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

* Re: [PATCH] PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash
  2017-02-15 23:06     ` Pedro Alves
@ 2017-02-16  0:57       ` Sergio Durigan Junior
  0 siblings, 0 replies; 6+ messages in thread
From: Sergio Durigan Junior @ 2017-02-16  0:57 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Doug Evans

On Wednesday, February 15 2017, Pedro Alves wrote:

> On 02/15/2017 10:54 PM, Sergio Durigan Junior wrote:
>> 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?
>> 
>> How about this?
>
> Awesome, thanks!  OK with minor nits.

Thanks for the review.  Pushed with all the minor nits fixed.

  99e8a4f9f8832da0f37c6f35b11629b01897800d

>> commit acd6597d63b2501588318466cd308701d09a58f3
>> Author: Sergio Durigan Junior <sergiodj@redhat.com>
>> Date:   Wed Feb 15 15:08:19 2017 -0500
>
>>     Hi,
>
> ...remove this above...
>
>>     This patch fixes that.  OK to apply?
>
> ...and this "OK" from the commit log and...
>
>> diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
>> index 2853508..b87cbfc 100644
>> --- a/gdb/testsuite/gdb.base/maint.exp
>> +++ b/gdb/testsuite/gdb.base/maint.exp
>> @@ -561,6 +561,14 @@ gdb_expect {
>>  
>>  #set timeout $oldtimeout
>>  
>> +# Testing that the commands work without an argument.  For this test,
>
> Write "Test that" here.
>
>> +# we don't need an inferior loaded/running.
>> +# See PR gdb/21164.
>> +gdb_exit
>> +gdb_start
>> +gdb_test_no_output "maint print symbols"
>> +gdb_test_no_output "maint print msymbols"
>> +gdb_test_no_output "maint print psymbols"
>
> Thanks,
> Pedro Alves

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

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

end of thread, other threads:[~2017-02-16  0:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-15 20:16 [PATCH] PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash Sergio Durigan Junior
2017-02-15 22:12 ` Pedro Alves
2017-02-15 22:48   ` Sergio Durigan Junior
2017-02-15 22:54   ` Sergio Durigan Junior
2017-02-15 23:06     ` Pedro Alves
2017-02-16  0:57       ` Sergio Durigan Junior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).