summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/lib/libc/gen
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2017-01-14 00:26:50 +0000
committerngie <ngie@FreeBSD.org>2017-01-14 00:26:50 +0000
commitcebfe1a4e0eee9575935b1baf0bfa28b5805a7b4 (patch)
treea11077ad879e1e929d5aa137967e5b1bc7e92acb /contrib/netbsd-tests/lib/libc/gen
parented40afe5519d7894d2af8745f165f9c19f403012 (diff)
downloadFreeBSD-src-cebfe1a4e0eee9575935b1baf0bfa28b5805a7b4.zip
FreeBSD-src-cebfe1a4e0eee9575935b1baf0bfa28b5805a7b4.tar.gz
MFC r311227,r311917:
r311227: seekdir_basic: fix various Coverity issues Address.. - .. resource leaks of file descriptors and memory - .. unchecked return values from creat(2), mkdir(2), and telldir(3) - .. potential NULL derefs after calling readdir(3) CID: 975255, 975256, 976989, 978989, 978990 r311917: Fix up r311227 Check for creat returning a value != -1, not a non-zero value Pointyhat to: ngie CID: 1368366
Diffstat (limited to 'contrib/netbsd-tests/lib/libc/gen')
-rw-r--r--contrib/netbsd-tests/lib/libc/gen/t_dir.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/libc/gen/t_dir.c b/contrib/netbsd-tests/lib/libc/gen/t_dir.c
index a6ab9e8..3b4c6cb 100644
--- a/contrib/netbsd-tests/lib/libc/gen/t_dir.c
+++ b/contrib/netbsd-tests/lib/libc/gen/t_dir.c
@@ -39,6 +39,10 @@
#include <sys/stat.h>
+#ifdef __FreeBSD__
+#include <errno.h>
+#endif
+
ATF_TC(seekdir_basic);
ATF_TC_HEAD(seekdir_basic, tc)
{
@@ -54,10 +58,26 @@ ATF_TC_BODY(seekdir_basic, tc)
struct dirent *entry;
long here;
+#ifdef __FreeBSD__
+#define CREAT(x, m) do { \
+ int _creat_fd; \
+ ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))) != -1, \
+ "creat(%s, %x) failed: %s", (x), (m), \
+ strerror(errno)); \
+ (void)close(_creat_fd); \
+ } while(0);
+
+ ATF_REQUIRE_MSG(mkdir("t", 0755) == 0,
+ "mkdir failed: %s", strerror(errno));
+ CREAT("t/a", 0600);
+ CREAT("t/b", 0600);
+ CREAT("t/c", 0600);
+#else
mkdir("t", 0755);
creat("t/a", 0600);
creat("t/b", 0600);
creat("t/c", 0600);
+#endif
dp = opendir("t");
if ( dp == NULL)
@@ -70,9 +90,17 @@ ATF_TC_BODY(seekdir_basic, tc)
/* get first entry */
entry = readdir(dp);
here = telldir(dp);
+#ifdef __FreeBSD__
+ ATF_REQUIRE_MSG(here != -1,
+ "telldir failed: %s", strerror(errno));
+#endif
/* get second entry */
entry = readdir(dp);
+#ifdef __FreeBSD__
+ ATF_REQUIRE_MSG(entry != NULL,
+ "readdir failed: %s", strerror(errno));
+#endif
wasname = strdup(entry->d_name);
if (wasname == NULL)
atf_tc_fail("cannot allocate memory");
@@ -109,6 +137,9 @@ ATF_TC_BODY(seekdir_basic, tc)
atf_tc_fail("3rd seekdir found wrong name");
closedir(dp);
+#ifdef __FreeBSD__
+ free(wasname);
+#endif
}
/* There is no sbrk on AArch64 and RISC-V */
OpenPOWER on IntegriCloud