From patchwork Tue Aug 28 09:48:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Fortran] PR54382 - fix invalid mem access in show_locus Date: Mon, 27 Aug 2012 23:48:15 -0000 From: Tobias Burnus X-Patchwork-Id: 180392 Message-Id: <503C93DF.4000001@net-b.de> To: gcc patches , gfortran 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 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++)