From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24620 invoked by alias); 8 Jan 2010 13:59:19 -0000 Received: (qmail 24609 invoked by uid 22791); 8 Jan 2010 13:59:18 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 08 Jan 2010 13:59:15 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 605F72BAB6F; Fri, 8 Jan 2010 08:59:13 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id A15bjDyIQfnH; Fri, 8 Jan 2010 08:59:13 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id D1EB62BAB40; Fri, 8 Jan 2010 08:59:12 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 0DDE7F595E; Fri, 8 Jan 2010 17:59:04 +0400 (RET) Date: Fri, 08 Jan 2010 13:59:00 -0000 From: Joel Brobecker To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFC] GDB crash with empty executable name (MinGW) Message-ID: <20100108135904.GG29312@adacore.com> References: <20100102124622.GW548@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="cNdxnHkX5QqsyA0e" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) 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: 2010-01/txt/msg00170.txt.bz2 --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 275 > I think it would be fine, but I would recommend putting some info into > the comment explaining why this check was added... just some detail from > your original note. Agreed. Here is what I checked in. I can make additional adjustments if necessary. Thank you! -- Joel --cNdxnHkX5QqsyA0e Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="source.diff" Content-length: 1182 commit f15ba96bbf48880f5a60443e78bab39070a5fc33 Author: Joel Brobecker Date: Fri Jan 8 16:15:54 2010 +0400 GDB crash with empty executable name (MinGW). * source.c (openp): Add assert that parameter string is not NULL. if parameter string is an empty string, then return with a failure immediately. diff --git a/gdb/source.c b/gdb/source.c index fcfce65..2090326 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -707,6 +707,20 @@ openp (const char *path, int opts, const char *string, /* The open syscall MODE parameter is not specified. */ gdb_assert ((mode & O_CREAT) == 0); + gdb_assert (string != NULL); + + /* A file with an empty name cannot possibly exist. Report a failure + without further checking. + + This is an optimization which also defends us against buggy + implementations of the "stat" function. For instance, we have + noticed that a MinGW debugger built on Windows XP 32bits crashes + when the debugger is started with an empty argument. */ + if (string[0] == '\0') + { + errno = ENOENT; + return -1; + } if (!path) path = "."; --cNdxnHkX5QqsyA0e--