From 726b4dc9681ebba0df3d2ea26736e2a60a0d3284 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 20 Jan 2016 15:36:20 -0700 Subject: [PATCH] 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. --- src/sudo_edit.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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); } -- 2.50.1