This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH 07/17] Regex: Additional memory management checks.
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Arnold Robbins <arnold at skeeve dot com>, carlos at redhat dot com, libc-alpha at sourceware dot org
- Cc: Gnulib bugs <bug-gnulib at gnu dot org>
- Date: Tue, 19 Dec 2017 17:04:51 -0800
- Subject: Re: [PATCH 07/17] Regex: Additional memory management checks.
- Authentication-results: sourceware.org; auth=none
- References: <201712080916.vB89GxcF005503@skeeve.com>
On 12/08/2017 01:16 AM in
+ /* some malloc()-checkers don't like zero allocations */
+ if (preg->re_nsub > 0)
dfa->subexp_map = re_malloc (int, preg->re_nsub);
+ dfa->subexp_map = NULL;
Which checkers are these? Can they be told that 'malloc (0)' is OK?
Since the code here is fine (i.e. it will work even if 'malloc (0)'
succeeds and returns NULL) it may be better to leave the code alone and
to fix the checkers instead.
+ * ADR: valgrind says size can be 0, which then doesn't
+ * free the block of size 0. Harumph. This seems
+ * to work ok, though.
+ if (size == 0)
+ memset(set, 0, sizeof(*set));
+ return REG_NOERROR;
set->alloc = size;
set->nelem = 0;
set->elems = re_malloc (int, size);
For this, how about if we use the corresponding Gnulib fix instead? An
advantage of the Gnulib fix is that it doesn't introduce runtime
overhead when glibc is used. Here is a URL:
diff --git a/posix/regexec.c b/posix/regexec.c
index 2d2bc46..8573765 100644
@@ -605,7 +605,7 @@ re_search_internal (const regex_t *preg, const char *string, int length,
nmatch -= extra_nmatch;
/* Check if the DFA haven't been compiled. */
- if (BE (preg->used == 0 || dfa->init_state == NULL
+ if (BE (preg->used == 0 || dfa == NULL || dfa->init_state == NULL
|| dfa->init_state_word == NULL || dfa->init_state_nl == NULL
|| dfa->init_state_begbuf == NULL, 0))
Why is this change needed? I couldn't see a code path that would trigger
it. Obviously I'm missing something. I suggest mentioning the reason in