From owner-svn-src-all@FreeBSD.ORG Thu Dec 12 02:05:00 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 61116F57; Thu, 12 Dec 2013 02:05:00 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4D0731F63; Thu, 12 Dec 2013 02:05:00 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBC250k2060656; Thu, 12 Dec 2013 02:05:00 GMT (envelope-from mdf@svn.freebsd.org) Received: (from mdf@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBC250iP060654; Thu, 12 Dec 2013 02:05:00 GMT (envelope-from mdf@svn.freebsd.org) Message-Id: <201312120205.rBC250iP060654@svn.freebsd.org> From: Matthew D Fleming Date: Thu, 12 Dec 2013 02:05:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r259243 - stable/9/contrib/gcclibs/libcpp X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Dec 2013 02:05:00 -0000 Author: mdf Date: Thu Dec 12 02:04:59 2013 New Revision: 259243 URL: http://svnweb.freebsd.org/changeset/base/259243 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/9/contrib/gcclibs/libcpp/errors.c Directory Properties: stable/9/contrib/gcclibs/ (props changed) Modified: stable/9/contrib/gcclibs/libcpp/errors.c ============================================================================== --- stable/9/contrib/gcclibs/libcpp/errors.c Thu Dec 12 02:03:42 2013 (r259242) +++ stable/9/contrib/gcclibs/libcpp/errors.c Thu Dec 12 02:04:59 2013 (r259243) @@ -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))