From unknown Wed Jun 25 00:24:00 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17499: current dfa.c can malloc 0 bytes Resent-From: Aharon Robbins Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Thu, 15 May 2014 16:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 17499 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: 17499@debbugs.gnu.org X-Debbugs-Original-To: bug-grep@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.140017101328926 (code B ref -1); Thu, 15 May 2014 16:24:02 +0000 Received: (at submit) by debbugs.gnu.org; 15 May 2014 16:23:33 +0000 Received: from localhost ([127.0.0.1]:36274 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkyRQ-0007WT-7q for submit@debbugs.gnu.org; Thu, 15 May 2014 12:23:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60882) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkyRO-0007WD-7L for submit@debbugs.gnu.org; Thu, 15 May 2014 12:23:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkyR9-0007h8-De for submit@debbugs.gnu.org; Thu, 15 May 2014 12:23:25 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_MANY_HDRS_LCASE autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36207) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkyR9-0007h2-BZ for submit@debbugs.gnu.org; Thu, 15 May 2014 12:23:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkyR0-00047g-IH for bug-grep@gnu.org; Thu, 15 May 2014 12:23:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkyQt-0007ZJ-1X for bug-grep@gnu.org; Thu, 15 May 2014 12:23:06 -0400 Received: from mxout1.netvision.net.il ([194.90.9.20]:60621) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkyQs-0007ZC-Qg for bug-grep@gnu.org; Thu, 15 May 2014 12:22:58 -0400 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII Received: from skeeve.com ([89.139.11.172]) by mxout1.netvision.net.il (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPS id <0N5M00COXITUAY20@mxout1.netvision.net.il> for bug-grep@gnu.org; Thu, 15 May 2014 19:22:43 +0300 (IDT) Received: from skeeve.com (skeeve.com [127.0.0.1]) by skeeve.com (8.14.4/8.14.4/Debian-2ubuntu2.1) with ESMTP id s4FGMf1t005099 for ; Thu, 15 May 2014 19:22:41 +0300 Received: (from arnold@localhost) by skeeve.com (8.14.4/8.14.4/Submit) id s4FGMelw005098 for bug-grep@gnu.org; Thu, 15 May 2014 19:22:40 +0300 From: Aharon Robbins Message-id: <201405151622.s4FGMelw005098@skeeve.com> Date: Thu, 15 May 2014 19:22:40 +0300 User-Agent: Heirloom mailx 12.5 6/20/10 X-detected-operating-system: by eggs.gnu.org: Solaris 10 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Hello. It seems that code in the grep master dfa.c can call xmalloc with an amount that is zero. This is OK on GLIBC but is causing some failures on other systems where malloc(0) fails. This was not the case a while back (when gawk 4.1.1 was released in April or so). It'd be nice if this could be fixed sometime. To test this in gawk, Apply the patch below to either master or gawk-4.1-stable from the git repo and rebuild, and make check. Gawk 4.1.1 doesn't have this problem. Thanks Arnold --------------- diff --git a/gawkmisc.c b/gawkmisc.c index a729d88..b07281d 100644 --- a/gawkmisc.c +++ b/gawkmisc.c @@ -52,6 +52,8 @@ pointer xmalloc(size_t bytes) { pointer p; + if (bytes == 0) + fprintf(stderr, "%s: 0 bytes!\n", __func__), fflush(stderr); emalloc(p, pointer, bytes, "xmalloc"); return p; } From unknown Wed Jun 25 00:24:00 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17499: current dfa.c can malloc 0 bytes Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Thu, 15 May 2014 16:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17499 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Aharon Robbins , 17499@debbugs.gnu.org Received: via spool by 17499-submit@debbugs.gnu.org id=B17499.140017253831690 (code B ref 17499); Thu, 15 May 2014 16:49:02 +0000 Received: (at 17499) by debbugs.gnu.org; 15 May 2014 16:48:58 +0000 Received: from localhost ([127.0.0.1]:36292 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wkyq1-0008Ez-Qy for submit@debbugs.gnu.org; Thu, 15 May 2014 12:48:58 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:49586) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wkypz-0008Ej-RM for 17499@debbugs.gnu.org; Thu, 15 May 2014 12:48:56 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 2615FA60036; Thu, 15 May 2014 09:48:50 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SWBtrL-3+nla; Thu, 15 May 2014 09:48:41 -0700 (PDT) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 5A994A60057; Thu, 15 May 2014 09:48:41 -0700 (PDT) Message-ID: <5374EFE9.7070303@cs.ucla.edu> Date: Thu, 15 May 2014 09:48:41 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 References: <201405151622.s4FGMelw005098@skeeve.com> In-Reply-To: <201405151622.s4FGMelw005098@skeeve.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -3.0 (---) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.0 (---) On 05/15/2014 09:22 AM, Aharon Robbins wrote: > It seems that code in the grep master dfa.c can call xmalloc with > an amount that is zero. This is OK on GLIBC but is causing some failures > on other systems where malloc(0) fails. Thanks, I'll try to take a look at this from your recipe. Are there any more details about the failure? What are the symptoms? A quick look at the dfa.c source code in grep suggests that it can't be a direct call to xmalloc, as those args all must be nonzero. Perhaps it's indirect, via xnmalloc or something like that? Also, gnulib's xmalloc doesn't mind if malloc (0) returns NULL. Is gawk's xmalloc pickier? If so, why? From unknown Wed Jun 25 00:24:00 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Aharon Robbins Subject: bug#17499: closed (Re: bug#17499: current dfa.c can malloc 0 bytes) Message-ID: References: <53751919.40307@cs.ucla.edu> <201405151622.s4FGMelw005098@skeeve.com> X-Gnu-PR-Message: they-closed 17499 X-Gnu-PR-Package: grep Reply-To: 17499@debbugs.gnu.org Date: Thu, 15 May 2014 19:45:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1400183103-25244-1" This is a multi-part message in MIME format... ------------=_1400183103-25244-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #17499: current dfa.c can malloc 0 bytes which was filed against the grep package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 17499@debbugs.gnu.org. --=20 17499: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D17499 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1400183103-25244-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 17499-done) by debbugs.gnu.org; 15 May 2014 19:44:38 +0000 Received: from localhost ([127.0.0.1]:36379 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wl1a2-0006YE-8p for submit@debbugs.gnu.org; Thu, 15 May 2014 15:44:38 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:32817) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wl1a0-0006Xw-42 for 17499-done@debbugs.gnu.org; Thu, 15 May 2014 15:44:37 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id DDD64A60036; Thu, 15 May 2014 12:44:29 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nL4m4rSRaYT3; Thu, 15 May 2014 12:44:25 -0700 (PDT) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id A0CA5A60064; Thu, 15 May 2014 12:44:25 -0700 (PDT) Message-ID: <53751919.40307@cs.ucla.edu> Date: Thu, 15 May 2014 12:44:25 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Aharon Robbins Subject: Re: bug#17499: current dfa.c can malloc 0 bytes References: <201405151622.s4FGMelw005098@skeeve.com> <5374EFE9.7070303@cs.ucla.edu> <201405151734.s4FHYaS4006573@skeeve.com> In-Reply-To: <201405151734.s4FHYaS4006573@skeeve.com> Content-Type: multipart/mixed; boundary="------------060309040707070005030403" X-Spam-Score: -3.0 (---) X-Debbugs-Envelope-To: 17499-done Cc: 17499-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.0 (---) This is a multi-part message in MIME format. --------------060309040707070005030403 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 05/15/2014 10:34 AM, Aharon Robbins wrote: > The wrapper only checks for NULL return. Ah, thanks, that's the problem then: gawk's xmalloc is pickier than grep's, and the extra pickiness is incompatible with what dfa.c expects. I see that gawk's xrealloc is also too picky, but gawk's xcalloc is OK. Attached isa patch to gawk. As this problem does not affect grep I'll close the grep bug. --------------060309040707070005030403 Content-Type: text/x-patch; name="0001-Port-to-systems-where-malloc-0-and-or-realloc-P-0-re.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Port-to-systems-where-malloc-0-and-or-realloc-P-0-re.pa"; filename*1="tch" >From 77b003848b85f83537b3f618cb0a810447329500 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 15 May 2014 12:37:48 -0700 Subject: [PATCH] Port to systems where malloc (0) and/or realloc(P, 0) returns NULL. * gawkmisc.c (xmalloc): * xalloc.h (realloc): Do not fail if malloc(0) or realloc(P, 0) returns NULL. Fail only when the allocator returns null when attempting to allocate a nonzero number of bytes. --- ChangeLog | 9 +++++++++ gawkmisc.c | 5 +++-- xalloc.h | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 45125c1..20dac99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2014-05-15 Paul Eggert + + Port to systems where malloc (0) and/or realloc(P, 0) returns NULL. + * gawkmisc.c (xmalloc): + * xalloc.h (realloc): + Do not fail if malloc(0) or realloc(P, 0) returns NULL. + Fail only when the allocator returns null when attempting to + allocate a nonzero number of bytes. + 2014-05-14 Arnold D. Robbins * custom.h (_GL_PURE): Move definition to here. Sigh. diff --git a/gawkmisc.c b/gawkmisc.c index a729d88..fff5cc5 100644 --- a/gawkmisc.c +++ b/gawkmisc.c @@ -51,7 +51,8 @@ extern pointer xmalloc(size_t bytes); /* get rid of gcc warning */ pointer xmalloc(size_t bytes) { - pointer p; - emalloc(p, pointer, bytes, "xmalloc"); + pointer p = malloc(bytes); + if (!p && bytes) + xalloc_die (); return p; } diff --git a/xalloc.h b/xalloc.h index 0d169cf..5ee4516 100644 --- a/xalloc.h +++ b/xalloc.h @@ -156,7 +156,7 @@ void * xrealloc(void *p, size_t size) { void *new_p = realloc(p, size); - if (new_p == 0) + if (!new_p && size) xalloc_die (); return new_p; -- 1.9.0 --------------060309040707070005030403-- ------------=_1400183103-25244-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 15 May 2014 16:23:33 +0000 Received: from localhost ([127.0.0.1]:36274 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkyRQ-0007WT-7q for submit@debbugs.gnu.org; Thu, 15 May 2014 12:23:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60882) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkyRO-0007WD-7L for submit@debbugs.gnu.org; Thu, 15 May 2014 12:23:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkyR9-0007h8-De for submit@debbugs.gnu.org; Thu, 15 May 2014 12:23:25 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_MANY_HDRS_LCASE autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36207) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkyR9-0007h2-BZ for submit@debbugs.gnu.org; Thu, 15 May 2014 12:23:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkyR0-00047g-IH for bug-grep@gnu.org; Thu, 15 May 2014 12:23:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkyQt-0007ZJ-1X for bug-grep@gnu.org; Thu, 15 May 2014 12:23:06 -0400 Received: from mxout1.netvision.net.il ([194.90.9.20]:60621) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkyQs-0007ZC-Qg for bug-grep@gnu.org; Thu, 15 May 2014 12:22:58 -0400 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII Received: from skeeve.com ([89.139.11.172]) by mxout1.netvision.net.il (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPS id <0N5M00COXITUAY20@mxout1.netvision.net.il> for bug-grep@gnu.org; Thu, 15 May 2014 19:22:43 +0300 (IDT) Received: from skeeve.com (skeeve.com [127.0.0.1]) by skeeve.com (8.14.4/8.14.4/Debian-2ubuntu2.1) with ESMTP id s4FGMf1t005099 for ; Thu, 15 May 2014 19:22:41 +0300 Received: (from arnold@localhost) by skeeve.com (8.14.4/8.14.4/Submit) id s4FGMelw005098 for bug-grep@gnu.org; Thu, 15 May 2014 19:22:40 +0300 From: Aharon Robbins Message-id: <201405151622.s4FGMelw005098@skeeve.com> Date: Thu, 15 May 2014 19:22:40 +0300 To: bug-grep@gnu.org Subject: current dfa.c can malloc 0 bytes User-Agent: Heirloom mailx 12.5 6/20/10 X-detected-operating-system: by eggs.gnu.org: Solaris 10 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Hello. It seems that code in the grep master dfa.c can call xmalloc with an amount that is zero. This is OK on GLIBC but is causing some failures on other systems where malloc(0) fails. This was not the case a while back (when gawk 4.1.1 was released in April or so). It'd be nice if this could be fixed sometime. To test this in gawk, Apply the patch below to either master or gawk-4.1-stable from the git repo and rebuild, and make check. Gawk 4.1.1 doesn't have this problem. Thanks Arnold --------------- diff --git a/gawkmisc.c b/gawkmisc.c index a729d88..b07281d 100644 --- a/gawkmisc.c +++ b/gawkmisc.c @@ -52,6 +52,8 @@ pointer xmalloc(size_t bytes) { pointer p; + if (bytes == 0) + fprintf(stderr, "%s: 0 bytes!\n", __func__), fflush(stderr); emalloc(p, pointer, bytes, "xmalloc"); return p; } ------------=_1400183103-25244-1--