This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[Patch, Fortran] PR54382 - fix invalid mem access in show_locus
- From: Tobias Burnus <burnus at net-b dot de>
- To: gcc patches <gcc-patches at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>
- Date: Tue, 28 Aug 2012 11:48:15 +0200
- Subject: [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++)