diff mbox series

Fix out-of-bounds in gcov.c (PR gcov-profile/85871).

Message ID 4870fc93-44b7-bfce-d3f1-5f8db6286ff2@suse.cz
State New
Headers show
Series Fix out-of-bounds in gcov.c (PR gcov-profile/85871). | expand

Commit Message

Martin Liška Sept. 17, 2018, 10:16 a.m. UTC
Hi.

One obvious patch where we access src->lines one element after the end.

Survives gcov.exp tests, I'm going to install the patch.

Martin

gcc/ChangeLog:

2018-09-17  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/85871
	* gcov.c (output_intermediate_file): Fix out of bounds
	access.
---
 gcc/gcov.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 6a24a320046..c6cf79b0f53 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -1085,7 +1085,8 @@  output_intermediate_file (FILE *gcov_file, source_info *src)
 	}
 
       /* Follow with lines associated with the source file.  */
-      output_intermediate_line (gcov_file, &src->lines[line_num], line_num);
+      if (line_num < src->lines.size ())
+	output_intermediate_line (gcov_file, &src->lines[line_num], line_num);
     }
 }