From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28526 invoked by alias); 1 Jul 2007 15:56:17 -0000 Received: (qmail 28515 invoked by uid 22791); 1 Jul 2007 15:56:16 -0000 X-Spam-Check-By: sourceware.org Received: from NaN.false.org (HELO nan.false.org) (208.75.86.248) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 01 Jul 2007 15:56:14 +0000 Received: from nan.false.org (localhost [127.0.0.1]) by nan.false.org (Postfix) with ESMTP id 5D3C0982BB; Sun, 1 Jul 2007 15:56:13 +0000 (GMT) Received: from caradoc.them.org (22.svnf5.xdsl.nauticom.net [209.195.183.55]) by nan.false.org (Postfix) with ESMTP id 40F56982B8; Sun, 1 Jul 2007 15:56:13 +0000 (GMT) Received: from drow by caradoc.them.org with local (Exim 4.67) (envelope-from ) id 1I51m3-00038a-1F; Sun, 01 Jul 2007 11:55:43 -0400 Date: Sun, 01 Jul 2007 15:56:00 -0000 From: Daniel Jacobowitz To: msnyder@sonic.net Cc: gdb-patches@sourceware.org Subject: Re: [OB] cli/cli-script.c, null ptr guard Message-ID: <20070701155543.GF10872@caradoc.them.org> Mail-Followup-To: msnyder@sonic.net, gdb-patches@sourceware.org References: <13902.12.7.175.2.1183067383.squirrel@webmail.sonic.net> <20070628215829.GA10350@caradoc.them.org> <6989.12.7.175.2.1183069038.squirrel@webmail.sonic.net> <20070628224250.GB12578@caradoc.them.org> <10837.12.7.175.2.1183071869.squirrel@webmail.sonic.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <10837.12.7.175.2.1183071869.squirrel@webmail.sonic.net> User-Agent: Mutt/1.5.15 (2007-04-09) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-07/txt/msg00011.txt.bz2 On Thu, Jun 28, 2007 at 04:04:29PM -0700, Michael Snyder wrote: > > On Thu, Jun 28, 2007 at 03:17:18PM -0700, msnyder@sonic.net wrote: > >> > No, I don't think this is obvious. What does it mean to have a null > >> > string here and how can it happen? I'm pretty sure it can't, and the > >> > if check is just clutter. > >> > >> The reasoning is that, since we checked it for NULL in the > >> first statement of the function, we must believe that the > >> possibility exists for it to be NULL. > > > > Right. So, is it a sensible check? Or should it be removed, or > > should the condition for the error be simplified? > > Well, it either makes sense to check it for null, or it doesn't. > If the new test is redundant, so is the old one. Whoever wrote > it in the first place seemed to think it was worth checking. > > This is called from a number of places, but they are all local to the module. > > Ultimately the argument comes from the command parser. > It's one of those typical (char *args, int from_tty) things. There's four calls to build_command_line. Three are passed a freshly incremented pointer, so it can never be NULL. That's if/while/commands. The other one came from get_command_line. Those can be NULL - well, I'm not sure, but I think they can. They're always if/while. So how about adding gdb_assert (args != NULL) after the error call, like below? If you follow where the result of this function goes, if we actually set cmd->line = NULL we will crash. -- Daniel Jacobowitz CodeSourcery 2007-07-01 Daniel Jacobowitz * cli/cli-script.c (build_command_line): Update NULL check. Index: cli/cli-script.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-script.c,v retrieving revision 1.41 diff -u -p -r1.41 cli-script.c --- cli/cli-script.c 28 Jun 2007 21:48:54 -0000 1.41 +++ cli/cli-script.c 1 Jul 2007 15:55:26 -0000 @@ -85,6 +85,7 @@ build_command_line (enum command_control if (args == NULL && (type == if_control || type == while_control)) error (_("if/while commands require arguments.")); + gdb_assert (args != NULL); cmd = (struct command_line *) xmalloc (sizeof (struct command_line)); cmd->next = NULL; @@ -95,8 +96,7 @@ build_command_line (enum command_control = (struct command_line **) xmalloc (sizeof (struct command_line *) * cmd->body_count); memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count); - if (args != NULL) - cmd->line = savestring (args, strlen (args)); + cmd->line = savestring (args, strlen (args)); return cmd; }