[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep-2.6.3 build feedback
From: |
Jim Meyering |
Subject: |
Re: grep-2.6.3 build feedback |
Date: |
Wed, 07 Apr 2010 13:39:39 +0200 |
Nelson H. F. Beebe wrote:
...
> On OSF/1 Alpha, compilation failed like this:
>
> CC kwset.o
> kwset.c: In function `kwsalloc':
> kwset.c:101: error: `malloc' undeclared (first use in this function)
> kwset.c:101: error: (Each undeclared identifier is reported only once
> kwset.c:101: error: for each function it appears in.)
>
> I trapped the preprocessor output, and found that the line
>
> obstack_init(&kwset->obstack);
>
> expands to
>
> _obstack_begin ((&kwset->obstack), 0, 0,
> (void *(*) (long)) malloc,
> (void (*) (void *)) free);
>
> I replaced the line kwset.c:45
>
> # define malloc(s) xmalloc(s)
>
> by
>
> # define malloc xmalloc
>
> because malloc appears without an argument list in the definition of
> _obstack_begin() in lib/obstack.h from the setting
>
> #define obstack_chunk_alloc malloc
>
> in kwset.c.
>
> Compilation then completed successfully, and all tests passed, EXCEPT
> for the three tests listed above.
Hi Nelson,
Thanks for the report.
I debated whether to add an entry to NEWS, but opted not to,
since it is unlikely that anyone will see the result of this fix.
Here's the patch:
>From 651d212abe771d2a32db746895ae28dd434527b6 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 7 Apr 2010 13:36:02 +0200
Subject: [PATCH] grep: make kwset's obstack use xmalloc, not malloc
This insidious bug could make grep fail to diagnose a failed malloc,
and then proceed to dereference the resulting NULL pointer.
Note that this bug was unlikely ever to cause real trouble; without
the fix, grep would segfault upon OOM, now it exits with a diagnostic.
* src/kwset.c (malloc) [GREP]: Define without the "(s)" macro
parameter, so that unadorned uses of malloc are also mapped to xmalloc.
One such use is in the expansion of obstack_init.
Report and patch by Nelson H. F. Beebe, in
http://thread.gmane.org/gmane.comp.gnu.grep.bugs/2995
---
src/kwset.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/kwset.c b/src/kwset.c
index 050562e..995be79 100644
--- a/src/kwset.c
+++ b/src/kwset.c
@@ -40,7 +40,7 @@
#ifdef GREP
# include "xalloc.h"
# undef malloc
-# define malloc(s) xmalloc(s)
+# define malloc xmalloc
#endif
#define NCHAR (UCHAR_MAX + 1)
--
1.7.1.rc0.212.gbd88f