From 9211bd33ec1c0923b992e9644cb94303b0fa3420 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Mon, 18 Feb 2013 07:17:12 +0000 Subject: [PATCH] [Sanitizer] Make temporary filename depend on user ID llvm-svn: 175424 --- compiler-rt/lib/sanitizer_common/sanitizer_common.h | 1 + compiler-rt/lib/sanitizer_common/sanitizer_posix.cc | 4 ++++ compiler-rt/lib/sanitizer_common/sanitizer_win.cc | 4 ++++ .../lib/sanitizer_common/tests/sanitizer_libc_test.cc | 12 +++++++----- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index ef09594..7816306 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -126,6 +126,7 @@ void DumpProcessMap(); bool FileExists(const char *filename); const char *GetEnv(const char *name); const char *GetPwd(); +u32 GetUid(); void ReExec(); bool StackSizeIsUnlimited(); void SetStackSizeLimitInBytes(uptr limit); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc index 05ed604..d072025 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc @@ -44,6 +44,10 @@ int GetPid() { return getpid(); } +u32 GetUid() { + return getuid(); +} + uptr GetThreadSelf() { return (uptr)pthread_self(); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc index 2ce3c35..4fe3ece 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc @@ -131,6 +131,10 @@ const char *GetPwd() { UNIMPLEMENTED(); } +u32 GetUid() { + UNIMPLEMENTED(); +} + void DumpProcessMap() { UNIMPLEMENTED(); } diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc index 6616f42..0ae2091 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc @@ -55,22 +55,24 @@ TEST(SanitizerCommon, FileOps) { const char *str2 = "zxcv"; uptr len2 = internal_strlen(str2); - const char kTempFileName[] = "/tmp/sanitizer_common.tmp"; - fd_t fd = OpenFile(kTempFileName, true); + u32 uid = GetUid(); + char temp_filename[128]; + internal_snprintf(temp_filename, 128, "/tmp/sanitizer_common.tmp.%d", uid); + fd_t fd = OpenFile(temp_filename, true); EXPECT_NE(fd, kInvalidFd); EXPECT_EQ(len1, internal_write(fd, str1, len1)); EXPECT_EQ(len2, internal_write(fd, str2, len2)); internal_close(fd); - fd = OpenFile(kTempFileName, false); + fd = OpenFile(temp_filename, false); EXPECT_NE(fd, kInvalidFd); uptr fsize = internal_filesize(fd); EXPECT_EQ(len1 + len2, fsize); #if SANITIZER_TEST_HAS_STAT_H struct stat st1, st2, st3; - EXPECT_EQ(0, internal_stat(kTempFileName, &st1)); - EXPECT_EQ(0, internal_lstat(kTempFileName, &st2)); + EXPECT_EQ(0, internal_stat(temp_filename, &st1)); + EXPECT_EQ(0, internal_lstat(temp_filename, &st2)); EXPECT_EQ(0, internal_fstat(fd, &st3)); EXPECT_EQ(fsize, (uptr)st3.st_size); #endif -- 2.7.4