This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug in tradcpp.c and patch fixing it


there is a bug in gcc/tradcpp.c which can potentially cause a segfault.

[actually, it does: CLISP uses cccp.c from GCC 1.42 for broken C
 compilers, like MSVC, the bug was already there and it caused us lots
 of pain.  We cannot - unfortunately - use a more modern GCC
 distribution since the broken compilers we are dealing with need the
 preprocessor to output line commands in the old "#line NUM" format.]

the problem is that obufp_before_macroname points inside op->buf, which
might be modified by RECACHE, thus RECACHE must update
obufp_before_macroname too.

the patch which fixes the bug, made against the files in the GCC-3.0
distribution, is appended to this message.

Thanks.

-- 
Sam Steingold (http://www.podval.org/~sds)
Support Israel's right to defend herself! <http://www.i-charity.com/go/israel>
Read what the Arab leaders say to their people on <http://www.memri.org/>
Hard work has a future payoff.  Laziness pays off NOW.


--- gcc/ChangeLog.old	Thu Aug 16 11:01:10 2001
+++ gcc/ChangeLog	Thu Aug 16 11:06:36 2001
@@ -1,3 +1,8 @@
+2001-08-16  Sam Steingold  <sds@gnu.org>
+
+	* tradcpp.c (rescan): define obufp_before_macroname before RECACHE
+	(RECACHE): keep obufp_before_macroname up to date
+
 20010617 Release Manager
 
         * GCC 3.0 Released.
--- gcc/tradcpp.c.old	Thu Aug 16 11:01:10 2001
+++ gcc/tradcpp.c	Thu Aug 16 11:05:46 2001
@@ -1220,6 +1220,9 @@
   /* Record position of last `real' newline.  */
   U_CHAR *beg_of_line;
 
+  /* This has to be a global bacause of RECACHE */
+  U_CHAR *obufp_before_macroname = NULL;
+
 /* Pop the innermost input stack level, assuming it is a macro expansion.  */
 
 #define POPMACRO \
@@ -1237,6 +1240,7 @@
      op->bufp = obp;			\
      check_expand (op, limit - ibp);	\
      beg_of_line = 0;			\
+     obufp_before_macroname += op->bufp - obp;  \
      obp = op->bufp; } while (0)
 
   if (no_output && instack[indepth].fname != 0)
@@ -1647,7 +1651,8 @@
 	     hp = hp->next) {
 
 	  if (hp->length == ident_length) {
-	    U_CHAR *obufp_before_macroname;
+	    /* obufp_before_macroname is used only in this block,
+               but it has to be global because of RECACHE */
 	    int op_lineno_before_macroname;
 	    register int i = ident_length;
 	    register U_CHAR *p = hp->name;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]