NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/51808: [PATCH] tests/lib/libc/gen/t_dir: fix various coverity issues
The following reply was made to PR bin/51808; it has been noted by GNATS.
From: "Ngie Cooper (yaneurabeya)" <yaneurabeya%gmail.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: bin/51808: [PATCH] tests/lib/libc/gen/t_dir: fix various coverity
issues
Date: Tue, 10 Jan 2017 01:20:30 -0800
--Apple-Mail=_6CF90D6D-4840-409A-8FFE-79C6423DA33A
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=us-ascii
Patch attached.
--Apple-Mail=_6CF90D6D-4840-409A-8FFE-79C6423DA33A
Content-Disposition: attachment;
filename=t_dir-fix-coverity-issues.patch
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="t_dir-fix-coverity-issues.patch"
Content-Transfer-Encoding: 7bit
Index: t_dir.c
===================================================================
RCS file: /cvsroot/src/tests/lib/libc/gen/t_dir.c,v
retrieving revision 1.6
diff -u -r1.6 t_dir.c
--- t_dir.c 19 Oct 2013 17:45:00 -0000 1.6
+++ t_dir.c 10 Jan 2017 09:16:18 -0000
@@ -26,18 +26,19 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <atf-c.h>
-
+#include <sys/stat.h>
#include <assert.h>
+#include <atf-c.h>
#include <dirent.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <sys/stat.h>
+
ATF_TC(seekdir_basic);
ATF_TC_HEAD(seekdir_basic, tc)
@@ -54,10 +55,19 @@
struct dirent *entry;
long here;
- mkdir("t", 0755);
- creat("t/a", 0600);
- creat("t/b", 0600);
- creat("t/c", 0600);
+#define CREAT(x, m) do { \
+ int _creat_fd; \
+ ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))), \
+ "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);
dp = opendir("t");
if ( dp == NULL)
@@ -70,6 +80,8 @@
/* get first entry */
entry = readdir(dp);
here = telldir(dp);
+ ATF_REQUIRE_MSG(here != -1,
+ "telldir failed: %s", strerror(errno));
/* get second entry */
entry = readdir(dp);
@@ -109,6 +121,7 @@
atf_tc_fail("3rd seekdir found wrong name");
closedir(dp);
+ free(wasname);
}
ATF_TC(telldir_leak);
--Apple-Mail=_6CF90D6D-4840-409A-8FFE-79C6423DA33A--
Home |
Main Index |
Thread Index |
Old Index