Blob Blame History Raw
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'.

--- libc/misc/regexp.h	19 May 2004 16:52:44 -0000	1.12
+++ libc/misc/regexp.h	6 Jun 2008 19:23:39 -0000	1.13
@@ -129,8 +130,9 @@ compile (char *__restrict instring, char
   __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
 	}
       __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
       }
 
   /* Everything is ok.  */
-  RETURN ((char *) (__expr_ptr->buffer + __expr_ptr->used));
+  RETURN ((char *) (__expr_ptr->__REPB_PREFIX (buffer)
+		    + __expr_ptr->__REPB_PREFIX (used)));
 }
 #endif