diff options
author | mdf <mdf@FreeBSD.org> | 2013-12-12 02:03:42 +0000 |
---|---|---|
committer | mdf <mdf@FreeBSD.org> | 2013-12-12 02:03:42 +0000 |
commit | cf9afebc6a89230e1c6e4972c4ca3bccd81a4750 (patch) | |
tree | 3d3918b92257dc5eec9879c2c364c02650724896 /contrib/gcclibs/libcpp | |
parent | 346b651e7c689cdfc0381ab30c7bebb4ca95dc0f (diff) | |
download | FreeBSD-src-cf9afebc6a89230e1c6e4972c4ca3bccd81a4750.zip FreeBSD-src-cf9afebc6a89230e1c6e4972c4ca3bccd81a4750.tar.gz |
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.
Diffstat (limited to 'contrib/gcclibs/libcpp')
-rw-r--r-- | contrib/gcclibs/libcpp/errors.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/contrib/gcclibs/libcpp/errors.c b/contrib/gcclibs/libcpp/errors.c index 97de490..c8efd53 100644 --- a/contrib/gcclibs/libcpp/errors.c +++ b/contrib/gcclibs/libcpp/errors.c @@ -153,7 +153,20 @@ cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) } 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)) |