From: Todd C. Miller Date: Wed, 20 Jan 2016 22:36:20 +0000 (-0700) Subject: If the user runs "sudoedit /" we will receive ENOENT from openat(2) X-Git-Tag: SUDO_1_8_16^2~52 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=726b4dc9681ebba0df3d2ea26736e2a60a0d3284;p=sudo 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. --- diff --git a/src/sudo_edit.c b/src/sudo_edit.c index 15abf1183..02bd9219e 100644 --- a/src/sudo_edit.c +++ b/src/sudo_edit.c @@ -411,7 +411,12 @@ sudo_edit_open_nonwritable(char *path, int oflags, mode_t mode, 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); debug_return_int(fd); }