svn commit: r258658 - head/contrib/gcclibs/libcpp

Matthew D Fleming mdf at FreeBSD.org
Tue Nov 26 17:11:44 UTC 2013


Author: mdf
Date: Tue Nov 26 17:11:43 2013
New Revision: 258658
URL: http://svnweb.freebsd.org/changeset/base/258658

Log:
  Fix a segfault / internal compiler error.
  
  Among other causes, when gcc throws a warning before parsing any tokens,
  the cur_token pointer is at the beginning of malloc'd memory.
  Dereferencing cur_token[-1] can cause a segfault.
  
  Code taken from OpenBSD
  http://www.openbsd.org/cgi-bin/cvsweb/src/gnu/gcc/libcpp/errors.c
  which was a more complete fix than the one I originally coded.
  
  MFC after:	1 week

Modified:
  head/contrib/gcclibs/libcpp/errors.c

Modified: head/contrib/gcclibs/libcpp/errors.c
==============================================================================
--- head/contrib/gcclibs/libcpp/errors.c	Tue Nov 26 16:13:48 2013	(r258657)
+++ head/contrib/gcclibs/libcpp/errors.c	Tue Nov 26 17:11:43 2013	(r258658)
@@ -153,7 +153,20 @@ cpp_error (cpp_reader * pfile, int level
 	}
       else
 	{
-	  src_loc = pfile->cur_token[-1].src_loc;
+	  /* Find actual previous token.  */
+	  cpp_token *t;
+
+	  if (pfile->cur_token != pfile->cur_run->base)
+	    t = pfile->cur_token - 1;
+	  else
+	    {
+	      if (pfile->cur_run->prev != NULL)
+	        t = pfile->cur_run->prev->limit;
+	      else
+	        t = NULL;
+	    }
+	  /* Retrieve corresponding source location, unless we failed.  */
+	  src_loc = t ? t->src_loc : 0;
 	}
 
       if (_cpp_begin_message (pfile, level, src_loc, 0))


More information about the svn-src-all mailing list