public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR preprocessor/58893 access to uninitialized memory
@ 2014-09-26 12:16 Bernd Edlinger
  2014-09-26 12:19 ` Marek Polacek
  2014-09-26 12:21 ` FW: " Bernd Edlinger
  0 siblings, 2 replies; 8+ messages in thread
From: Bernd Edlinger @ 2014-09-26 12:16 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jeff Law, Joseph S. Myers

Hi,

this patch fixes PR58893, which is an access to uninitialized memory, which may or may not crash in
linemap_resolve_location, or just print error messages with bogus location.

When the first -include file is processed we have the case, where
pfile->cur_token == pfile->cur_run->base, this is directly called
by the front end. However in the case of the second -include file,
this is called from  _cpp_lex_token -> _cpp_get_fresh_line ->
cpp_push_include, with pfile->cur_token != pfile->cur_run->base,
and pfile->cur_token[-1].src_loc and token not (yet) initialized.
The problem is, when the include file cannot be found, we need
src_loc to be initialized to some safe value: 0 means UNKNOWN_LOCATION.

Regarding the hunk in cpp_diagnostic, which is not directly involved
in this bug, but it is still obviously wrong:

The line "src_loc = pfile->cur_run->prev->limit->src_loc"
is probably unreachable, but will crash it is ever executed.

see:

_cpp_init_tokenrun (tokenrun *run, unsigned int count)
{
  run->base = XNEWVEC (cpp_token, count);
  run->limit = run->base + count;
  run->next = NULL;
}

so, limit points at the end of the run.


Boot-Strapped and Regression-tested on x86_64-linux-gnu
Ok for trunk?


Thanks
Bernd.
 		 	   		  

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-09-30 16:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-26 12:16 [PATCH] Fix PR preprocessor/58893 access to uninitialized memory Bernd Edlinger
2014-09-26 12:19 ` Marek Polacek
2014-09-26 12:21 ` FW: " Bernd Edlinger
2014-09-26 18:48   ` Jeff Law
     [not found]     ` <DUB118-W46D6B67D3766B4DE9B85D7E4BC0@phx.gbl>
2014-09-27  9:53       ` Bernd Edlinger
2014-09-30  4:41         ` Jeff Law
2014-09-30  9:01           ` Bernd Edlinger
2014-09-30 16:38             ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).