Patchwork [Fortran] PR54382 - fix invalid mem access in show_locus

login
register
mail settings
Submitter Tobias Burnus
Date Aug. 28, 2012, 9:48 a.m.
Message ID <503C93DF.4000001@net-b.de>
Download mbox | patch
Permalink /patch/180392/
State New
Headers show

Comments

Tobias Burnus - Aug. 28, 2012, 9:48 a.m.
I intent to commit the attached patch as obvious. The current code has:

   cmax = (c1 < c2) ? c2 : c1;
   if (cmax > terminal_width - 5)
     offset = cmax - terminal_width + 5;
...
   c1 -= offset;
   c2 -= offset;

   p = &(lb->line[offset]);
   for (i = 0; i <= cmax; i++)
     {
       int spaces, j;
       spaces = gfc_widechar_display_length (*p++);

where "line[offset+cmax]" might be a too large index.


Build on x86-64-linux. (I still have to regtest.)


Tobias

Patch

2012-08-28  Tobias Burnus  <burnus@net-b.de>

	PR fortran/54382
	* error.c (show_locus): Avoid out of bound access.

diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index dde6a0f..64b9357 100644
--- a/gcc/fortran/error.c
+++ b/gcc/fortran/error.c
@@ -384,6 +384,7 @@  show_locus (locus *loc, int c1, int c2)
 
   c1 -= offset;
   c2 -= offset;
+  cmax -= offset;
 
   p = &(lb->line[offset]);
   for (i = 0; i <= cmax; i++)