[compiler-rt] r302639 - [msan] Fix getmntent{_r} for empty /etc/fstab
Adhemerval Zanella via llvm-commits
llvm-commits at lists.llvm.org
Wed May 10 05:18:26 PDT 2017
Author: azanella
Date: Wed May 10 07:18:25 2017
New Revision: 302639
URL: http://llvm.org/viewvc/llvm-project?rev=302639&view=rev
Log:
[msan] Fix getmntent{_r} for empty /etc/fstab
Some configuration (for instance default docker ubuntu images) uses
a default empty and invalid /etc/fstab configuration file. It makes
any call to getmntent return NULL and it leads to failures on
Msan-aarch64{-with-call}-Test/MemorySanitizer.getmntent{_r}.
This patch fixes it by creating a temporary file with some valid
entries (although not valid for the system) to use along with
setmntent/getmntent.
Modified:
compiler-rt/trunk/lib/msan/tests/msan_test.cc
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=302639&r1=302638&r2=302639&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Wed May 10 07:18:25 2017
@@ -2203,10 +2203,51 @@ TEST(MemorySanitizer, localtime_r) {
EXPECT_NE(0U, strlen(time.tm_zone));
}
+#if !defined(__FreeBSD__)
+/* Creates a temporary file with contents similar to /etc/fstab to be used
+ with getmntent{_r}. */
+class TempFstabFile {
+ public:
+ TempFstabFile() : fd (-1) { }
+ ~TempFstabFile() {
+ if (fd >= 0)
+ close (fd);
+ }
+
+ bool Create(void) {
+ snprintf(tmpfile, sizeof(tmpfile), "/tmp/msan.getmntent.tmp.XXXXXX");
+
+ fd = mkstemp(tmpfile);
+ if (fd == -1)
+ return false;
+
+ const char entry[] = "/dev/root / ext4 errors=remount-ro 0 1";
+ size_t entrylen = sizeof(entry);
+
+ size_t bytesWritten = write(fd, entry, entrylen);
+ if (entrylen != bytesWritten)
+ return false;
+
+ return true;
+ }
+
+ const char* FileName(void) {
+ return tmpfile;
+ }
+
+ private:
+ char tmpfile[128];
+ int fd;
+};
+#endif
+
// There's no getmntent() on FreeBSD.
#if !defined(__FreeBSD__)
TEST(MemorySanitizer, getmntent) {
- FILE *fp = setmntent("/etc/fstab", "r");
+ TempFstabFile fstabtmp;
+ ASSERT_TRUE(fstabtmp.Create());
+ FILE *fp = setmntent(fstabtmp.FileName(), "r");
+
struct mntent *mnt = getmntent(fp);
ASSERT_TRUE(mnt != NULL);
ASSERT_NE(0U, strlen(mnt->mnt_fsname));
@@ -2222,7 +2263,10 @@ TEST(MemorySanitizer, getmntent) {
// There's no getmntent_r() on FreeBSD.
#if !defined(__FreeBSD__)
TEST(MemorySanitizer, getmntent_r) {
- FILE *fp = setmntent("/etc/fstab", "r");
+ TempFstabFile fstabtmp;
+ ASSERT_TRUE(fstabtmp.Create());
+ FILE *fp = setmntent(fstabtmp.FileName(), "r");
+
struct mntent mntbuf;
char buf[1000];
struct mntent *mnt = getmntent_r(fp, &mntbuf, buf, sizeof(buf));
More information about the llvm-commits
mailing list