From b4cdd9352af07228c5af18399f67b55f9683409b Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 29 May 2017 11:12:33 +0200 Subject: [PATCH] Backport r246961 2017-05-29 Martin Liska Backport from mainline 2017-04-18 Martin Liska PR gcov-profile/78783 * gcov-tool.c (gcov_output_files): Validate that destination file is either removed by the tool or by a user. 2017-05-29 Martin Liska Backport from mainline 2017-04-18 Martin Liska PR gcov-profile/78783 * libgcov-driver.c (gcov_get_filename): New function. From-SVN: r248566 --- gcc/ChangeLog | 9 +++++++++ gcc/gcov-tool.c | 9 +++++++++ libgcc/ChangeLog | 8 ++++++++ libgcc/libgcov-driver.c | 9 +++++++++ 4 files changed, 35 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 78389055a72f..8f417fcb6e8e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2017-05-29 Martin Liska + + Backport from mainline + 2017-04-18 Martin Liska + + PR gcov-profile/78783 + * gcov-tool.c (gcov_output_files): Validate that destination + file is either removed by the tool or by a user. + 2017-05-29 Martin Liska Backport from mainline diff --git a/gcc/gcov-tool.c b/gcc/gcov-tool.c index fd27d7c11ad0..3a8dfc1ca8ba 100644 --- a/gcc/gcov-tool.c +++ b/gcc/gcov-tool.c @@ -46,6 +46,7 @@ extern int gcov_profile_normalize (struct gcov_info*, gcov_type); extern int gcov_profile_scale (struct gcov_info*, float, int, int); extern struct gcov_info* gcov_read_profile_dir (const char*, int); extern void gcov_do_dump (struct gcov_info *, int); +extern const char *gcov_get_filename (struct gcov_info *list); extern void gcov_set_verbose (void); /* Set to verbose output mode. */ @@ -114,6 +115,14 @@ gcov_output_files (const char *out, struct gcov_info *profile) if (ret) fatal_error (input_location, "Cannot change directory to %s", out); + /* Verify that output file does not exist (either was removed by + unlink_profile_data or removed by user). */ + const char *filename = gcov_get_filename (profile); + + if (access (filename, F_OK) != -1) + fatal_error (input_location, "output file %s already exists in folder %s", + filename, out); + gcov_do_dump (profile, 0); ret = chdir (pwd); diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index 2a13b0d11e27..4d0f580a146b 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,11 @@ +2017-05-29 Martin Liska + + Backport from mainline + 2017-04-18 Martin Liska + + PR gcov-profile/78783 + * libgcov-driver.c (gcov_get_filename): New function. + 2017-05-19 Andreas Tobler Backport from mainline diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c index 221ac0c00d05..4886c5d100ff 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -848,6 +848,15 @@ gcov_do_dump (struct gcov_info *list, int run_counted) free (gf.filename); } +#if IN_GCOV_TOOL +const char * +__attribute__ ((unused)) +gcov_get_filename (struct gcov_info *list) +{ + return list->filename; +} +#endif + #if !IN_GCOV_TOOL void __gcov_dump_one (struct gcov_root *root) -- 2.47.2