]> granicus.if.org Git - zfs/commitdiff
Fix coverity defects: CID 147536, 147537, 147538
authorGeLiXin <ge.lixin@zte.com.cn>
Fri, 30 Sep 2016 22:40:07 +0000 (06:40 +0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 30 Sep 2016 22:40:07 +0000 (15:40 -0700)
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 <behlendorf1@llnl.gov>
Signed-off-by: GeLiXin <ge.lixin@zte.com.cn>
Closes #5185

cmd/zed/zed_exec.c [changed mode: 0644->0755]
tests/zfs-tests/cmd/dir_rd_update/dir_rd_update.c [changed mode: 0644->0755]
tests/zfs-tests/cmd/rm_lnkcnt_zero_file/rm_lnkcnt_zero_file.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 1d040cc..1a3b76d
@@ -106,10 +106,11 @@ _zed_exec_fork_child(uint64_t eid, const char *dir, const char *prog,
                return;
        } else if (pid == 0) {
                (void) umask(022);
-               fd = open("/dev/null", O_RDWR);
-               (void) dup2(fd, STDIN_FILENO);
-               (void) dup2(fd, STDOUT_FILENO);
-               (void) dup2(fd, STDERR_FILENO);
+               if ((fd = open("/dev/null", O_RDWR)) != -1) {
+                       (void) dup2(fd, STDIN_FILENO);
+                       (void) dup2(fd, STDOUT_FILENO);
+                       (void) dup2(fd, STDERR_FILENO);
+               }
                (void) dup2(zfd, ZEVENT_FILENO);
                zed_file_close_from(ZEVENT_FILENO + 1);
                execle(path, prog, NULL, env);
old mode 100644 (file)
new mode 100755 (executable)
index 4a2fa65..3e075e3
@@ -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);
old mode 100644 (file)
new mode 100755 (executable)
index ee85a20..7986851
@@ -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");