GNU bug report logs - #17499
current dfa.c can malloc 0 bytes

Previous Next

Package: grep;

Reported by: Aharon Robbins <arnold <at> skeeve.com>

Date: Thu, 15 May 2014 16:24:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 17499 in the body.
You can then email your comments to 17499 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#17499; Package grep. (Thu, 15 May 2014 16:24:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Aharon Robbins <arnold <at> skeeve.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Thu, 15 May 2014 16:24:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Aharon Robbins <arnold <at> skeeve.com>
To: bug-grep <at> gnu.org
Subject: current dfa.c can malloc 0 bytes
Date: Thu, 15 May 2014 19:22:40 +0300
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;
 }




Information forwarded to bug-grep <at> gnu.org:
bug#17499; Package grep. (Thu, 15 May 2014 16:49:02 GMT) Full text and rfc822 format available.

Message #8 received at 17499 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Aharon Robbins <arnold <at> skeeve.com>, 17499 <at> debbugs.gnu.org
Subject: Re: bug#17499: current dfa.c can malloc 0 bytes
Date: Thu, 15 May 2014 09:48:41 -0700
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?




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Thu, 15 May 2014 19:45:02 GMT) Full text and rfc822 format available.

Notification sent to Aharon Robbins <arnold <at> skeeve.com>:
bug acknowledged by developer. (Thu, 15 May 2014 19:45:03 GMT) Full text and rfc822 format available.

Message #13 received at 17499-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Aharon Robbins <arnold <at> skeeve.com>
Cc: 17499-done <at> debbugs.gnu.org
Subject: Re: bug#17499: current dfa.c can malloc 0 bytes
Date: Thu, 15 May 2014 12:44:25 -0700
[Message part 1 (text/plain, inline)]
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.


[0001-Port-to-systems-where-malloc-0-and-or-realloc-P-0-re.patch (text/x-patch, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 13 Jun 2014 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 14 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.