[PATCH] D32800: [msan] Fix getmntent{_r} for empty /etc/fstab
Adhemerval Zanella via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 3 06:33:39 PDT 2017
zatrazz created this revision.
zatrazz added a project: Sanitizers.
Herald added a subscriber: aemerson.
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.
https://reviews.llvm.org/D32800
Files:
lib/msan/tests/msan_test.cc
Index: lib/msan/tests/msan_test.cc
===================================================================
--- lib/msan/tests/msan_test.cc
+++ lib/msan/tests/msan_test.cc
@@ -2203,10 +2203,44 @@
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() { unlink(tmpfile); }
+
+ void Create(void) {
+ snprintf(tmpfile, sizeof(tmpfile), "/tmp/msan.getmntent.tmp.XXXXXX");
+
+ int fd = mkstemp(tmpfile);
+ ASSERT_NE(fd, -1);
+
+ const char entry[] = "/dev/root / ext4 errors=remount-ro 0 1";
+ size_t entrylen = sizeof(entry);
+
+ size_t bytes_written = write (fd, entry, entrylen);
+ EXPECT_EQ(entrylen, bytes_written);
+
+ close(fd);
+ }
+
+ const char *FileName(void) {
+ return tmpfile;
+ }
+
+ private:
+ char tmpfile[128];
+};
+#endif
+
// There's no getmntent() on FreeBSD.
#if !defined(__FreeBSD__)
TEST(MemorySanitizer, getmntent) {
- FILE *fp = setmntent("/etc/fstab", "r");
+ TempFstabFile fstabtmp;
+ 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 +2256,10 @@
// There's no getmntent_r() on FreeBSD.
#if !defined(__FreeBSD__)
TEST(MemorySanitizer, getmntent_r) {
- FILE *fp = setmntent("/etc/fstab", "r");
+ TempFstabFile fstabtmp;
+ fstabtmp.Create();
+ FILE *fp = setmntent(fstabtmp.FileName(), "r");
+
struct mntent mntbuf;
char buf[1000];
struct mntent *mnt = getmntent_r(fp, &mntbuf, buf, sizeof(buf));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32800.97623.patch
Type: text/x-patch
Size: 1699 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170503/0a4d9bc0/attachment.bin>
More information about the llvm-commits
mailing list