This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR54382 - fix invalid mem access in show_locus


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
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++)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]