When creating a new file, sudoedit will now check that the file's

parent directory exists before running the editor.
This commit is contained in:
Todd C. Miller
2015-10-24 06:20:20 -06:00
parent 7761af6d7e
commit 5d66b840d8
2 changed files with 18 additions and 2 deletions

3
NEWS
View File

@@ -83,6 +83,9 @@ What's new in Sudo 1.8.15
to the group plugin. Previously, unknown system groups were to the group plugin. Previously, unknown system groups were
always passed to the group plugin. 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 What's new in Sudo 1.8.14p3
* Fixed a bug introduced in sudo 1.8.14p2 that prevented sudo * Fixed a bug introduced in sudo 1.8.14p2 that prevented sudo

View 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); ofd = sudo_edit_open(files[i], O_RDONLY, 0644, command_details->flags);
if (ofd != -1 || errno == ENOENT) { if (ofd != -1 || errno == ENOENT) {
if (ofd == -1) { if (ofd == -1) {
memset(&sb, 0, sizeof(sb)); /* new file */ /* New file, verify parent dir exists unless in cwd. */
rc = 0; 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 { } else {
rc = fstat(ofd, &sb); rc = fstat(ofd, &sb);
} }