From patchwork Wed Feb 15 20:15:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 19267 Received: (qmail 25018 invoked by alias); 15 Feb 2017 20:16:06 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 25009 invoked by uid 89); 15 Feb 2017 20:16:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=2.9.3, sk:mainten, 21164, sk:symbols X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Feb 2017 20:16:05 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 196E680484; Wed, 15 Feb 2017 20:16:05 +0000 (UTC) Received: from psique.yyz.redhat.com (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1FKG4e2015812; Wed, 15 Feb 2017 15:16:04 -0500 From: Sergio Durigan Junior To: GDB Patches Cc: Doug Evans , Sergio Durigan Junior Subject: [PATCH] PR gdb/21164: maint print {symbols, msymbols, psymbols} without args crash Date: Wed, 15 Feb 2017 15:15:48 -0500 Message-Id: <20170215201548.29225-1-sergiodj@redhat.com> X-IsSubscribed: yes Hi, This is a fix for PR gdb/21164. The problem started to happen after: commit 34c41c681f4a0a0dfe0405c7d2aecf458520557a Author: Doug Evans 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 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;