]> granicus.if.org Git - sudo/commitdiff
When creating a new file, sudoedit will now check that the file's
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 24 Oct 2015 12:20:20 +0000 (06:20 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 24 Oct 2015 12:20:20 +0000 (06:20 -0600)
parent directory exists before running the editor.

NEWS
src/sudo_edit.c

diff --git a/NEWS b/NEWS
index c47334a29030636aed8252dce6caef4216a94a9d..ae2a232c1cf04826155cd9563e5f677ab83f9800 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -83,6 +83,9 @@ What's new in Sudo 1.8.15
    to the group plugin.  Previously, unknown system groups were
    always passed to the group plugin.
 
+ * When creating a new file, sudoedit will now check that the file's
+   parent directory exists before running the editor.
+
 What's new in Sudo 1.8.14p3
 
  * Fixed a bug introduced in sudo 1.8.14p2 that prevented sudo
index ca8442103ec851e368b3f97e4ba3e221a0d01fcb..6a2cec564e88ec053c19877b4e6242ad53a69145 100644 (file)
@@ -387,8 +387,21 @@ sudo_edit_create_tfiles(struct command_details *command_details,
        ofd = sudo_edit_open(files[i], O_RDONLY, 0644, command_details->flags);
        if (ofd != -1 || errno == ENOENT) {
            if (ofd == -1) {
-               memset(&sb, 0, sizeof(sb));             /* new file */
-               rc = 0;
+               /* New file, verify parent dir exists unless in cwd. */
+               char *slash = strrchr(files[i], '/');
+               if (slash != NULL && slash != files[i]) {
+                   int serrno = errno;
+                   *slash = '\0';
+                   if (stat(files[i], &sb) == 0 && S_ISDIR(sb.st_mode)) {
+                       memset(&sb, 0, sizeof(sb));
+                       rc = 0;
+                   }
+                   *slash = '/';
+                   errno = serrno;
+               } else {
+                   memset(&sb, 0, sizeof(sb));
+                   rc = 0;
+               }
            } else {
                rc = fstat(ofd, &sb);
            }