summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGeLiXin <[email protected]>2016-10-01 06:40:07 +0800
committerBrian Behlendorf <[email protected]>2016-09-30 15:40:07 -0700
commited3ea30fb9341c860c94bf71e771f115ee4801ea (patch)
tree524a0b15122fed6e8cf76d907e9149cc2d0f3df0 /tests
parent292d573e70d254f5011f20f0c4882e928fac594b (diff)
Fix coverity defects: CID 147536, 147537, 147538
coverity scan CID:147536, type: Argument cannot be negative - may write or close fd which is negative coverity scan CID:147537, type: Argument cannot be negative - may call dup2 with a negative fd coverity scan CID:147538, type: Argument cannot be negative - may read or fchown with a negative fd Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: GeLiXin <[email protected]> Closes #5185
Diffstat (limited to 'tests')
-rwxr-xr-x[-rw-r--r--]tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c12
-rwxr-xr-x[-rw-r--r--]tests/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c11
2 files changed, 20 insertions, 3 deletions
diff --git a/tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c b/tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c
index 4a2fa65f5..3e075e3d7 100644..100755
--- a/tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c
+++ b/tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c
@@ -94,6 +94,12 @@ main(int argc, char **argv)
int rdret;
int j = 0;
+ if (fd < 0) {
+ (void) printf("%s: open <%s> again failed:"
+ " errno = %d\n", argv[0], dirpath, errno);
+ exit(-1);
+ }
+
while (j < op_num) {
(void) sleep(1);
rdret = read(fd, buf, 16);
@@ -107,6 +113,12 @@ main(int argc, char **argv)
int chownret;
int k = 0;
+ if (fd < 0) {
+ (void) printf("%s: open(<%s>, O_RDONLY) again failed:"
+ " errno (decimal)=%d\n", argv[0], dirpath, errno);
+ exit(-1);
+ }
+
while (k < op_num) {
(void) sleep(1);
chownret = fchown(fd, 0, 0);
diff --git a/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c b/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c
index ee85a207d..7986851ef 100644..100755
--- a/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c
+++ b/tests/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c
@@ -103,10 +103,15 @@ writer(void *a)
int ret;
while (TRUE) {
- (void) close (*fd);
+ if (*fd != -1)
+ (void) close (*fd);
+
*fd = open(filebase, O_APPEND | O_RDWR | O_CREAT, 0644);
- if (*fd < 0)
- perror("refreshing file");
+ if (*fd == -1) {
+ perror("fail to open test file, refreshing it");
+ continue;
+ }
+
ret = write(*fd, "test\n", 5);
if (ret != 5)
perror("writing file");