Address the following defects reported by Coverity:
* Structurally dead code (CID
1404366): set m_quit before FAIL, not after
* Unchecked return value of sysctlbyname (CID
1404321)
* Unchecked return value of stat(2) (CID
1404471)
* Unchecked return value of open(2) (CID
1404402,
1404529)
* Unchecked return value of dup(2) (CID
1404478)
* Buffer overflows. These are all false positives caused by the fact that
Coverity thinks I'm using a buffer to store strings, when in fact I'm
really just using it to store a byte array that happens to be initialized
with a string. I'm changing the type from char to uint8_t in the hopes
that it will placate Coverity. (CID
1404338,
1404350,
1404367,
1404376,
1404379,
1404381,
1404388,
1404403,
1404425,
1404433,
1404434,
1404474,
1404480,
1404484,
1404503,
1404505)
* False positive file descriptor leak. I'm going to try to fix this with
Coverity modeling, but I'll also change an EXPECT to ASSERT so we don't
perform meaningless assertions after the failure. (CID
1404320,
1404324,
1404440,
1404445).
* Unannotated file descriptor leak. This will be followed up by a Coverity
modeling change. (CID
1404326,
1404334,
1404336,
1404357,
1404361,
1404372,
1404391,
1404395,
1404409,
1404430,
1404448,
1404451,
1404455,
1404457,
1404458,
1404460)
* Uninitialized variables in C++ constructors (CID
1404327,
1404346). In the
case of m_maxphys, this actually led to part of the FUSE_INIT's response
being set to stack garbage during the WriteCluster::clustering test.
* Uninitialized sun_len field in struct sockaddr_un (CID
1404330,
1404371,
1404429).
Reported by: Coverity
Reviewed by: emaste
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D21457
}
);
ASSERT_EQ(0, WEXITSTATUS(status));
+
+ leak(dfd);
}
/*
EXPECT_EQ(arg.bn, lbn * m_maxbcachebuf / DEV_BSIZE);
EXPECT_EQ(arg.runp, 0);
EXPECT_EQ(arg.runb, m_maxphys / m_maxbcachebuf - 1);
+
+ leak(fd);
}
EXPECT_LOOKUP(FUSE_ROOT_ID, RELPATH)
.WillOnce(Invoke(ReturnErrno(ENOENT)));
- EXPECT_EQ(-1, open(FULLPATH, O_CREAT | O_EXCL, 0644));
+ ASSERT_EQ(-1, open(FULLPATH, O_CREAT | O_EXCL, 0644));
EXPECT_EQ(EACCES, errno);
}
struct stat sb;
name = (const char*)arg;
- stat(name, &sb);
- return 0;
+ return ((void*)(intptr_t)stat(name, &sb));
}
/*
* A kevent's data field should contain the number of operations available to
- * be immediately rea.
+ * be immediately read.
*/
TEST_F(Kqueue, data)
{
uint64_t bar_ino = 43;
uint64_t baz_ino = 44;
Sequence seq;
+ void *th_ret;
ASSERT_EQ(0, sem_init(&sem0, 0, 0)) << strerror(errno);
ASSERT_EQ(0, sem_init(&sem1, 0, 0)) << strerror(errno);
nap(); // Allow th1 and th2 to send their ops to the daemon
EXPECT_EQ(0, sem_post(&sem1)) << strerror(errno);
- pthread_join(th0, NULL);
- pthread_join(th1, NULL);
- pthread_join(th2, NULL);
+ pthread_join(th0, &th_ret);
+ ASSERT_EQ(-1, (intptr_t)th_ret);
+ pthread_join(th1, &th_ret);
+ ASSERT_EQ(-1, (intptr_t)th_ret);
+ pthread_join(th2, &th_ret);
+ ASSERT_EQ(-1, (intptr_t)th_ret);
EXPECT_EQ(1, nready0);
EXPECT_EQ(2, nready1);
}
sa.sun_family = AF_UNIX;
strlcpy(sa.sun_path, FULLPATH, sizeof(sa.sun_path));
+ sa.sun_len = sizeof(FULLPATH);
err = connect(fd, (struct sockaddr*)&sa, sizeof(sa));
if (err < 0) {
perror("connect");
sent += r;
}
+
+ FuseTest::leak(fd);
return 0;
}
ASSERT_LE(0, fd) << strerror(errno);
sa.sun_family = AF_UNIX;
strlcpy(sa.sun_path, FULLPATH, sizeof(sa.sun_path));
+ sa.sun_len = sizeof(FULLPATH);
ASSERT_EQ(0, bind(fd, (struct sockaddr*)&sa, sizeof(sa)))
<< strerror(errno);
listen(fd, 5);
EXPECT_EQ(0, (intptr_t)thr0_value);
sem_destroy(&sem1);
sem_destroy(&sem0);
+
+ leak(fd1);
}
/*
EXPECT_EQ(0, (intptr_t)thr0_value);
sem_destroy(&sem1);
sem_destroy(&sem0);
+
+ leak(fd1);
}
/*
setup_interruptor(self);
ASSERT_EQ(-1, read(fd, buf, bufsize));
EXPECT_EQ(EINTR, errno);
+
+ leak(fd);
}
/*
off_t m_filesize;
bool m_direct_io;
-Io(): m_backing_fd(-1), m_control_fd(-1), m_direct_io(false) {};
+Io(): m_backing_fd(-1), m_control_fd(-1), m_test_fd(-1), m_direct_io(false) {};
void SetUp()
{
ASSERT_LE(0, fd) << strerror(errno);
sa.sun_family = AF_UNIX;
strlcpy(sa.sun_path, FULLPATH, sizeof(sa.sun_path));
+ sa.sun_len = sizeof(FULLPATH);
ASSERT_EQ(0, bind(fd, (struct sockaddr*)&sa, sizeof(sa)))
<< strerror(errno);
+
+ leak(fd);
}
/*
res = read(m_fuse_fd, &in, sizeof(in));
if (res < 0 && !m_quit) {
- FAIL() << "read: " << strerror(errno);
m_quit = true;
+ FAIL() << "read: " << strerror(errno);
}
ASSERT_TRUE(res >= static_cast<ssize_t>(sizeof(in.header)) || m_quit);
/*
/* Fill the data cache */
fd = open(FULLPATH, O_RDWR);
+ ASSERT_LE(0, fd);
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
expect_write(ino, 0, bufsize, CONTENTS);
/* Fill the data cache */
fd = open(FULLPATH, O_RDWR);
+ ASSERT_LE(0, fd) << strerror(errno);
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
/* Evict the attributes, but not data cache */
}, Eq(true)),
_)
).WillOnce(Invoke(ReturnErrno(ENOENT)));
- EXPECT_NE(0, open(FULLPATH, O_RDONLY));
+ ASSERT_EQ(-1, open(FULLPATH, O_RDONLY));
EXPECT_EQ(ENOENT, errno);
}
}, Eq(true)),
_)
).WillOnce(Invoke(ReturnErrno(EPERM)));
- EXPECT_NE(0, open(FULLPATH, O_RDONLY));
+ ASSERT_EQ(-1, open(FULLPATH, O_RDONLY));
EXPECT_EQ(EPERM, errno);
}
expect_lookup(RELPATH, ino);
expect_opendir(ino, O_RDONLY, ReturnErrno(ENOENT));
- EXPECT_NE(0, open(FULLPATH, O_DIRECTORY));
+ ASSERT_EQ(-1, open(FULLPATH, O_DIRECTORY));
EXPECT_EQ(ENOENT, errno);
}
const char FULLPATH[] = "mountpoint/some_dir";
const char RELPATH[] = "some_dir";
uint64_t ino = 42;
+ int fd;
expect_lookup(RELPATH, ino);
expect_opendir(ino, O_RDONLY,
SET_OUT_HEADER_LEN(out, open);
}));
- EXPECT_LE(0, open(FULLPATH, O_DIRECTORY)) << strerror(errno);
+ fd = open(FULLPATH, O_DIRECTORY);
+ EXPECT_LE(0, fd) << strerror(errno);
+
+ leak(fd);
}
/* Directories can be opened O_EXEC for stuff like fchdir(2) */
fd = open(FULLPATH, O_EXEC | O_DIRECTORY);
ASSERT_LE(0, fd) << strerror(errno);
+
+ leak(fd);
}
TEST_F(Opendir, opendir)
uint64_t ino = 42;
int fd;
ssize_t bufsize = strlen(CONTENTS);
- char buf[bufsize];
+ uint8_t buf[bufsize];
struct aiocb iocb, *piocb;
expect_lookup(RELPATH, ino, bufsize);
int fd;
uint64_t offset = 100;
ssize_t bufsize = strlen(CONTENTS);
- char buf[bufsize];
+ uint8_t buf[bufsize];
expect_lookup(RELPATH, ino, offset + bufsize);
expect_open(ino, FOPEN_DIRECT_IO, 1);
uint64_t offset = 100;
ssize_t bufsize = strlen(CONTENTS);
ssize_t halfbufsize = bufsize / 2;
- char buf[bufsize];
+ uint8_t buf[bufsize];
expect_lookup(RELPATH, ino, offset + bufsize);
expect_open(ino, FOPEN_DIRECT_IO, 1);
uint64_t ino = 42;
int fd;
ssize_t bufsize = strlen(CONTENTS);
- char buf[bufsize];
+ uint8_t buf[bufsize];
expect_lookup(RELPATH, ino, bufsize);
expect_open(ino, 0, 1);
ssize_t bufsize = strlen(CONTENTS);
ssize_t partbufsize = 3 * bufsize / 4;
ssize_t r;
- char buf[bufsize];
+ uint8_t buf[bufsize];
struct stat sb;
expect_lookup(RELPATH, ino, offset + bufsize);
int fd;
ssize_t bufsize = strlen(CONTENTS);
off_t old_filesize = m_maxbcachebuf * 2 + bufsize;
- char buf[bufsize];
+ uint8_t buf[bufsize];
struct stat sb;
expect_lookup(RELPATH, ino, old_filesize);
uint64_t ino = 42;
int fd0, fd1;
ssize_t bufsize = strlen(CONTENTS);
- char buf[bufsize];
+ uint8_t buf[bufsize];
FuseTest::expect_lookup(RELPATH, ino, S_IFREG | 0644, bufsize, 2);
expect_open(ino, FOPEN_KEEP_CACHE, 2);
uint64_t ino = 42;
int fd0, fd1;
ssize_t bufsize = strlen(CONTENTS);
- char buf[bufsize];
+ uint8_t buf[bufsize];
FuseTest::expect_lookup(RELPATH, ino, S_IFREG | 0644, bufsize, 2);
expect_open(ino, 0, 2);
uint64_t ino = 42;
int fd;
ssize_t bufsize = strlen(CONTENTS);
- char buf[bufsize];
+ uint8_t buf[bufsize];
expect_lookup(RELPATH, ino, bufsize);
expect_open(ino, 0, 1);
*/
uint64_t offset = m_maxbcachebuf;
ssize_t bufsize = strlen(CONTENTS);
- char buf[bufsize];
+ uint8_t buf[bufsize];
expect_lookup(RELPATH, ino, offset + bufsize);
expect_open(ino, 0, 1);
uint64_t ino = 42;
int fd;
ssize_t bufsize = strlen(CONTENTS);
- char buf[bufsize];
+ uint8_t buf[bufsize];
expect_lookup(RELPATH, ino, bufsize);
expect_open(ino, 0, 1);
uint64_t ino = 42;
int fd;
ssize_t bufsize = strlen(CONTENTS);
- char buf[bufsize];
+ uint8_t buf[bufsize];
expect_lookup(RELPATH, ino, bufsize);
expect_open(ino, 0, 1);
uint64_t ino = 42;
int fd;
size_t bufsize = strlen(CONTENTS);
- char buf[bufsize];
+ uint8_t buf[bufsize];
int sp[2];
off_t sbytes;
EXPECT_LE(0, fd) << strerror(errno);
fd2 = dup(fd);
+ ASSERT_LE(0, fd2) << strerror(errno);
ASSERT_EQ(0, close(fd2)) << strerror(errno);
ASSERT_EQ(0, close(fd)) << strerror(errno);
free(r1buf);
free(r0buf);
free(w0buf);
+
+ leak(fd);
}
/* Change a file's timestamps */
GTEST_SKIP() << strerror(errno);
}
}
- sysctlbyname(usermount_node, &usermount_val, &usermount_size,
- NULL, 0);
+ ASSERT_EQ(sysctlbyname(usermount_node, &usermount_val, &usermount_size,
+ NULL, 0),
+ 0);;
if (geteuid() != 0 && !usermount_val)
GTEST_SKIP() << "current user is not allowed to mount";
}
m_async(false),
m_noclusterr(false),
m_nointr(false),
- m_time_gran(1)
+ m_time_gran(1),
+ m_maxbcachebuf(0),
+ m_maxphys(0)
{}
virtual void SetUp();
public:
virtual void SetUp() {
m_async = true;
- m_maxwrite = m_maxphys;
+ m_maxwrite = 1 << 25; // Anything larger than MAXPHYS will suffice
WriteBack::SetUp();
if (m_maxphys < 2 * DFLTPHYS)
GTEST_SKIP() << "MAXPHYS must be at least twice DFLTPHYS"
free(expected);
free(zeros);
+
+ leak(fd);
}
TEST_F(Write, pwrite)
EXPECT_EQ(sb0.st_atime, sb1.st_atime);
EXPECT_NE(sb0.st_mtime, sb1.st_mtime);
EXPECT_NE(sb0.st_ctime, sb1.st_ctime);
+
+ leak(fd);
}
TEST_F(Write, write)
uint64_t ino = 42;
int fd;
ssize_t bufsize = strlen(CONTENTS);
- char readbuf[bufsize];
+ uint8_t readbuf[bufsize];
expect_lookup(RELPATH, ino, 0);
expect_open(ino, 0, 1);
uint64_t ino = 42;
int fd;
ssize_t bufsize = strlen(CONTENTS);
- char readbuf[bufsize];
+ uint8_t readbuf[bufsize];
expect_lookup(RELPATH, ino, 0);
expect_open(ino, 0, 1);
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
/* Don't close the file because that would flush the cache */
+ leak(fd);
}
/*
EXPECT_EQ((time_t)server_time, sb.st_atime);
EXPECT_NE((time_t)server_time, sb.st_mtime);
EXPECT_NE((time_t)server_time, sb.st_ctime);
+
+ leak(fd);
}
/* Any dirty timestamp fields should be flushed during a SETATTR */
EXPECT_LE(0, fd) << strerror(errno);
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
ASSERT_EQ(0, fchmod(fd, newmode)) << strerror(errno);
+
+ leak(fd);
}
/* fuse_init_out.time_gran controls the granularity of timestamps */
EXPECT_LE(0, fd) << strerror(errno);
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
ASSERT_EQ(0, fchmod(fd, newmode)) << strerror(errno);
+
+ leak(fd);
}
INSTANTIATE_TEST_CASE_P(RA, TimeGran, Range(0u, 10u));
uint64_t ino = 42;
int fd;
ssize_t bufsize = strlen(CONTENTS);
- char readbuf[bufsize];
+ uint8_t readbuf[bufsize];
expect_lookup(RELPATH, ino, 0);
expect_open(ino, 0, 1);