summaryrefslogtreecommitdiff
path: root/misc/regexp.h
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2008-06-06 19:23:39 +0000
committerJakub Jelinek <jakub@redhat.com>2008-06-06 19:23:39 +0000
commiteef8a803a6846407fcd4955c3fb19036b6fac586 (patch)
tree4603c4e2037d20190a2d408ad5ff4ba6fdcea9f1 /misc/regexp.h
parentee78670e26f24777550cb2cc44c79f427477a59c (diff)
downloadglibc-eef8a803a6846407fcd4955c3fb19036b6fac586.tar.gz
* misc/regexp.h (compile): Use __REPB_PREFIX macro.
Avoid segfault if first GETC returns eof/'\0'/'\n'. 2008-06-05 Jakub Jelinek <jakub@redhat.com> * misc/regexp.h (compile): Use __REPB_PREFIX macro. Avoid segfault if first GETC returns eof/'\0'/'\n'.
Diffstat (limited to 'misc/regexp.h')
-rw-r--r--misc/regexp.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/misc/regexp.h b/misc/regexp.h
index b7b50b7105..0e979d2d87 100644
--- a/misc/regexp.h
+++ b/misc/regexp.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 1999, 2004, 2008
+ Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -129,8 +130,9 @@ compile (char *__restrict instring, char *__restrict expbuf,
__expr_ptr = (regex_t *) expbuf;
/* The remaining space in the buffer can be used for the compiled
pattern. */
- __expr_ptr->buffer = expbuf + sizeof (regex_t);
- __expr_ptr->allocated = endbuf - (char *) __expr_ptr->buffer;
+ __expr_ptr->__REPB_PREFIX (buffer) = expbuf + sizeof (regex_t);
+ __expr_ptr->__REPB_PREFIX (allocated)
+ = endbuf - (char *) __expr_ptr->__REPB_PREFIX (buffer);
while ((__ch = (GETC ())) != eof)
{
@@ -162,7 +164,10 @@ compile (char *__restrict instring, char *__restrict expbuf,
}
__input_buffer[__current_size++] = __ch;
}
- __input_buffer[__current_size++] = '\0';
+ if (__current_size)
+ __input_buffer[__current_size++] = '\0';
+ else
+ __input_buffer = "";
/* Now compile the pattern. */
__error = regcomp (__expr_ptr, __input_buffer, REG_NEWLINE);
@@ -198,7 +203,8 @@ compile (char *__restrict instring, char *__restrict expbuf,
}
/* Everything is ok. */
- RETURN ((char *) (__expr_ptr->buffer + __expr_ptr->used));
+ RETURN ((char *) (__expr_ptr->__REPB_PREFIX (buffer)
+ + __expr_ptr->__REPB_PREFIX (used)));
}
#endif