]> granicus.if.org Git - sudo/commitdiff
No need to check if fd_dst is -1 in sudoedit mode.
authorTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 19 Oct 2018 19:33:37 +0000 (13:33 -0600)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 19 Oct 2018 19:33:37 +0000 (13:33 -0600)
Failure to open the destination sudoedit file is fatal so there's
no need to check that fd_dst != -1 later on.  Found by PVS-Studio.

src/sesh.c

index c994fea4a6f842e72ce5fc33ad580c0ba625f4d8..9bbd062ee296ceb4e0e94763f687ed7484393268 100644 (file)
@@ -221,24 +221,24 @@ sesh_sudoedit(int argc, char *argv[])
            }
        }
 
-       if (fd_dst != -1) {
-           if (!post) {
-               if (fd_src == -1 || fstat(fd_src, &sb) != 0)
-                   memset(&sb, 0, sizeof(sb));
-               /* Make mtime on temp file match src. */
-               mtim_get(&sb, times[0]);
-               times[1].tv_sec = times[0].tv_sec;
-               times[1].tv_nsec = times[0].tv_nsec;
-               if (futimens(fd_dst, times) == -1) {
-                   if (utimensat(AT_FDCWD, path_dst, times, 0) == -1)
-                       sudo_warn("%s", path_dst);
-               }
+       if (!post) {
+           if (fd_src == -1 || fstat(fd_src, &sb) != 0)
+               memset(&sb, 0, sizeof(sb));
+           /* Make mtime on temp file match src. */
+           mtim_get(&sb, times[0]);
+           times[1].tv_sec = times[0].tv_sec;
+           times[1].tv_nsec = times[0].tv_nsec;
+           if (futimens(fd_dst, times) == -1) {
+               if (utimensat(AT_FDCWD, path_dst, times, 0) == -1)
+                   sudo_warn("%s", path_dst);
            }
-           close(fd_dst);
        }
-       if (fd_src != -1)
+       close(fd_dst);
+       fd_dst = -1;
+       if (fd_src != -1) {
            close(fd_src);
-       fd_dst = fd_src = -1;
+           fd_src = -1;
+       }
     }
 
     ret = SESH_SUCCESS;