If the user runs "sudoedit /" we will receive ENOENT from openat(2)

and sudoedit will try to create a file with the null string.  If
path is empty, open the cwd instead so sudoedit can give a sensible
error message.
This commit is contained in:
Todd C. Miller
2016-01-20 15:36:20 -07:00
parent 399ec8b2b0
commit 726b4dc968

View File

@@ -411,7 +411,12 @@ sudo_edit_open_nonwritable(char *path, int oflags, mode_t mode,
debug_return_int(-1); debug_return_int(-1);
} }
fd = openat(dfd, path, oflags, mode); /*
* For "sudoedit /" we will receive ENOENT from openat() and sudoedit
* will try to create a file with an empty name. We treat an empty
* path as the cwd so sudoedit can give a sensible error message.
*/
fd = openat(dfd, *path ? path : ".", oflags, mode);
close(dfd); close(dfd);
debug_return_int(fd); debug_return_int(fd);
} }