cpplib 20000414 bootstrap failure

Zack Weinberg zack@wolery.cumb.org
Sat Apr 15 10:49:00 GMT 2000


On Sat, Apr 15, 2000 at 09:34:49PM +1000, Alan Modra wrote:
> I have a bootstrap failure, seemingly due to a cpplib problem.  bootstrap
> compiler was gcc-2.95.1, glibc-2.1.2

This is being caused by access to garbage memory.  I am testing the
appended patch right now.

Ulrich, I believe this is the same bug you told me about privately.

zw

	* cpplex.c (_cpp_expand_to_buffer): Revert previous change:
	copy text before putting it on the input stack.
	(_cpp_read_and_prescan): Don't read past the end of the
	buffer.

===================================================================
Index: cpplex.c
--- cpplex.c	2000/04/14 23:29:45	1.13
+++ cpplex.c	2000/04/15 17:47:31
@@ -245,6 +245,7 @@ _cpp_expand_to_buffer (pfile, buf, lengt
 {
   cpp_buffer *ip;
   enum cpp_ttype token;
+  U_CHAR *buf1;
 
   if (length < 0)
     {
@@ -252,8 +253,14 @@ _cpp_expand_to_buffer (pfile, buf, lengt
       return;
     }
 
+  /* Copy the buffer, because it might be in an unsafe place - for
+     example, a sequence on the token_buffer, where the pointers will
+     be invalidated if we enlarge the token_buffer.  */
+  buf1 = xmalloc (length);
+  memcpy (buf1, buf, length);
+
   /* Set up the input on the input stack.  */
-  ip = cpp_push_buffer (pfile, buf, length);
+  ip = cpp_push_buffer (pfile, buf1, length);
   if (ip == NULL)
     return;
   ip->has_escapes = 1;
@@ -271,6 +278,7 @@ _cpp_expand_to_buffer (pfile, buf, lengt
 	}
     }
   CPP_NUL_TERMINATE (pfile);
+  free (buf1);
 }
 
 /* Scan until CPP_BUFFER (PFILE) is exhausted, discarding output.
@@ -1631,12 +1639,6 @@ _cpp_read_and_prescan (pfile, fp, desc, 
     {
       U_CHAR *near_buff_end;
 
-      /* Copy previous char plus unprocessed (at most 2) chars
-	 to beginning of buffer, refill it with another
-	 read(), and continue processing */
-      memcpy(ip - count - 1, ip - 1, 3);
-      ip -= count;
-
       count = read (desc, ibase, pfile->input_buffer_len);
       if (count < 0)
 	goto error;
@@ -1785,6 +1787,11 @@ _cpp_read_and_prescan (pfile, fp, desc, 
 	      break;
 	    }
 	}
+      /* Copy previous char plus unprocessed (at most 2) chars
+	 to beginning of buffer, refill it with another
+	 read(), and continue processing */
+      memmove (ip - count - 1, ip - 1, 3 - (ip - near_buff_end));
+      ip -= count;
     }
 
   if (offset == 0)
@@ -1795,7 +1802,7 @@ _cpp_read_and_prescan (pfile, fp, desc, 
       unsigned long col;
       line_base = find_position (line_base, op, &line);
       col = op - line_base + 1;
-      cpp_warning_with_line (pfile, line, col, "no newline at end of file\n");
+      cpp_warning_with_line (pfile, line, col, "no newline at end of file");
       if (offset + 1 > len)
 	{
 	  len += 1;
@@ -1811,7 +1818,8 @@ _cpp_read_and_prescan (pfile, fp, desc, 
   return op - buf;
 
  too_big:
-  cpp_error (pfile, "file is too large (>%lu bytes)\n", (unsigned long)offset);
+  cpp_notice (pfile, "%s is too large (>%lu bytes)", fp->ihash->name,
+	      (unsigned long)offset);
   free (buf);
   return -1;
 


More information about the Gcc-bugs mailing list