This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[patch] regex bug fix.
- To: libc-alpha at sourceware dot cygnus dot com
- Subject: [patch] regex bug fix.
- From: Isamu Hasegawa <isamu at yamato dot ibm dot com>
- Date: Thu, 29 Mar 2001 14:19:21 +0900 (JST)
- Cc: rodrigob at conectiva dot com dot br, shoji at jp dot ibm dot com
Hello,
Following test program will coredump if link with Electric Fence.
(Thanks Rodrigo Barbosa <rodrigob@conectiva.com.br>, he let me know
the problem.)
g++ -o crash crash.cc -lefence
=======
#include <sys/types.h>
#include <regex.h>
#include <string>
string some_staticaly_stanciated_object;
main ()
{
regex_t p;
regcomp(&p,"kernel",p);
}
=======
Then, the following patch can fix it, I think.
(I'm sorry, since I haven't gotten 2.2.3pre1 yet by temporary network problem,
this patch is against 2.2.2.)
2001-03-29 Isamu Hasegawa <isamu@yamato.ibm.com>
* posix/regex.c: fix typo and add a sentinel.
--- posix/regex.c.2.2.2 Fri Feb 16 14:49:59 2001
+++ posix/regex.c Thu Mar 29 13:48:36 2001
@@ -65,7 +65,7 @@
# define CHAR_CLASS_SIZE ((__alignof__(wctype_t)+sizeof(wctype_t))/sizeof(CHAR_TYPE)+1)
# define PUT_CHAR(c) \
do { \
- if (MC_CUR_MAX == 1) \
+ if (MB_CUR_MAX == 1) \
putchar (c); \
else \
printf ("%C", (wint_t) c); /* Should we use wide stream?? */ \
@@ -2346,7 +2346,8 @@ regex_compile (pattern, size, syntax, bu
#ifdef MBS_SUPPORT
/* Initialize the wchar_t PATTERN and offset_buffer. */
- p = pend = pattern = TALLOC(csize, CHAR_TYPE);
+ p = pend = pattern = TALLOC(csize + 1, CHAR_TYPE);
+ p[csize] = L'\0'; /* sentinel */
mbs_offset = TALLOC(csize + 1, int);
is_binary = TALLOC(csize + 1, char);
if (pattern == NULL || mbs_offset == NULL || is_binary == NULL)