summaryrefslogtreecommitdiff
path: root/cpio/test
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@gmail.com>2016-10-11 18:38:44 -0700
committerTim Kientzle <kientzle@gmail.com>2016-10-11 18:38:44 -0700
commita625b42f516cb5f6bf5b55323924b15ee8b717e9 (patch)
treeff26cae6e25f1a534e226489c73d935a619c293d /cpio/test
parentf767497395f3732ee88a542f1eaff884c37b71a6 (diff)
downloadlibarchive-a625b42f516cb5f6bf5b55323924b15ee8b717e9.tar.gz
Issue #801: close the file descriptor when testing link counts
Thanks to Ed Maste for reporting this leak. Found by: Coverity
Diffstat (limited to 'cpio/test')
-rw-r--r--cpio/test/main.c16
-rw-r--r--cpio/test/test.h5
2 files changed, 20 insertions, 1 deletions
diff --git a/cpio/test/main.c b/cpio/test/main.c
index 29bbc37a..f3b431d0 100644
--- a/cpio/test/main.c
+++ b/cpio/test/main.c
@@ -130,6 +130,13 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/main.c,v 1.3 2008/08/24 04:58:22 kient
# include <crtdbg.h>
#endif
+mode_t umasked(mode_t expected_mode)
+{
+ mode_t mode = umask(0);
+ umask(mode);
+ return expected_mode & ~mode;
+}
+
/* Path to working directory for current test */
const char *testworkdir;
#ifdef PROGRAM
@@ -1294,6 +1301,11 @@ assertion_file_time(const char *file, int line,
switch (type) {
case 'a': filet_nsec = st.st_atimespec.tv_nsec; break;
case 'b': filet = st.st_birthtime;
+ /* FreeBSD filesystems that don't support birthtime
+ * (e.g., UFS1) always return -1 here. */
+ if (filet == -1) {
+ return (1);
+ }
filet_nsec = st.st_birthtimespec.tv_nsec; break;
case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break;
default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type);
@@ -1425,7 +1437,7 @@ assertion_file_nlinks(const char *file, int line,
assertion_count(file, line);
r = lstat(pathname, &st);
if (r == 0 && (int)st.st_nlink == nlinks)
- return (1);
+ return (1);
failure_start(file, line, "File %s has %d links, expected %d",
pathname, st.st_nlink, nlinks);
failure_finish(NULL);
@@ -1661,6 +1673,7 @@ assertion_make_file(const char *file, int line,
if (0 != chmod(path, mode)) {
failure_start(file, line, "Could not chmod %s", path);
failure_finish(NULL);
+ close(fd);
return (0);
}
if (contents != NULL) {
@@ -1675,6 +1688,7 @@ assertion_make_file(const char *file, int line,
failure_start(file, line,
"Could not write to %s", path);
failure_finish(NULL);
+ close(fd);
return (0);
}
}
diff --git a/cpio/test/test.h b/cpio/test/test.h
index ecc6f279..0a8b31e1 100644
--- a/cpio/test/test.h
+++ b/cpio/test/test.h
@@ -182,6 +182,8 @@
assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks)
#define assertFileSize(pathname, size) \
assertion_file_size(__FILE__, __LINE__, pathname, size)
+#define assertFileMode(pathname, mode) \
+ assertion_file_mode(__FILE__, __LINE__, pathname, mode)
#define assertTextFileContents(text, pathname) \
assertion_text_file_contents(__FILE__, __LINE__, text, pathname)
#define assertFileContainsLinesAnyOrder(pathname, lines) \
@@ -327,6 +329,9 @@ void copy_reference_file(const char *);
*/
void extract_reference_files(const char **);
+/* Subtract umask from mode */
+mode_t umasked(mode_t expected_mode);
+
/* Path to working directory for current test */
extern const char *testworkdir;