Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Dec 2013 02:03:42 +0000 (UTC)
From:      Matthew D Fleming <mdf@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r259242 - stable/10/contrib/gcclibs/libcpp
Message-ID:  <201312120203.rBC23gm1060419@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mdf
Date: Thu Dec 12 02:03:42 2013
New Revision: 259242
URL: http://svnweb.freebsd.org/changeset/base/259242

Log:
  MFC r258658:
  
  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.

Modified:
  stable/10/contrib/gcclibs/libcpp/errors.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/contrib/gcclibs/libcpp/errors.c
==============================================================================
--- stable/10/contrib/gcclibs/libcpp/errors.c	Thu Dec 12 00:27:27 2013	(r259241)
+++ stable/10/contrib/gcclibs/libcpp/errors.c	Thu Dec 12 02:03:42 2013	(r259242)
@@ -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))



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312120203.rBC23gm1060419>