[compiler-rt] [compiler-rt][profile] Duplicate filename in `parseAndSetFilename` if exists (PR #110264)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 27 06:13:26 PDT 2024
https://github.com/antoniofrighetto created https://github.com/llvm/llvm-project/pull/110264
Duplicate `lprofCurFilename.FilenamePat` if the filename exists in `parseAndSetFilename`, as the original path name buffer may have been freed by the time it is used.
Fixes: https://github.com/llvm/llvm-project/issues/102109.
>From fc19a5d76a1dbaeec7d202d0d4766d91d7eed97f Mon Sep 17 00:00:00 2001
From: Antonio Frighetto <me at antoniofrighetto.com>
Date: Fri, 27 Sep 2024 15:10:44 +0200
Subject: [PATCH] [compiler-rt][profile] Duplicate filename in
`parseAndSetFilename` if exists
Duplicate `lprofCurFilename.FilenamePat` if the filename exists in
`parseAndSetFilename`, as the original path name buffer may have
been freed by the time it is used.
Fixes: https://github.com/llvm/llvm-project/issues/102109.
---
compiler-rt/lib/profile/InstrProfilingFile.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c
index 64ed8b62e9eba7..8243a7a5ea3ca9 100644
--- a/compiler-rt/lib/profile/InstrProfilingFile.c
+++ b/compiler-rt/lib/profile/InstrProfilingFile.c
@@ -894,7 +894,9 @@ static void parseAndSetFilename(const char *FilenamePat,
ProfileNameSpecifier PNS,
unsigned CopyFilenamePat) {
- const char *OldFilenamePat = lprofCurFilename.FilenamePat;
+ char *OldFilenamePat = lprofCurFilename.FilenamePat
+ ? strdup(lprofCurFilename.FilenamePat)
+ : NULL;
ProfileNameSpecifier OldPNS = lprofCurFilename.PNS;
/* The old profile name specifier takes precedence over the old one. */
@@ -923,6 +925,9 @@ static void parseAndSetFilename(const char *FilenamePat,
PROF_NOTE("Override old profile path \"%s\" via %s to \"%s\" via %s.\n",
OldFilenamePat, getPNSStr(OldPNS), lprofCurFilename.FilenamePat,
getPNSStr(PNS));
+
+ free(OldFilenamePat);
+ OldFilenamePat = NULL;
}
truncateCurrentFile();
More information about the llvm-commits
mailing list