From 5ec59cddc20cbad707d3e3c8165c4623de56d1f3 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 16 Feb 2021 13:19:58 -0700 Subject: [PATCH] Fix tilde expansion of paths with no user like ~/foo. The '/' separator was missing in the resulting path. --- plugins/sudoers/exptilde.c | 2 +- plugins/sudoers/regress/exptilde/check_exptilde.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/sudoers/exptilde.c b/plugins/sudoers/exptilde.c index 4a21a3225..bbdd09dbc 100644 --- a/plugins/sudoers/exptilde.c +++ b/plugins/sudoers/exptilde.c @@ -86,7 +86,7 @@ expand_tilde(char **path, const char *user) debug_return_bool(false); } - len = asprintf(&npath, "%s%s%s", pw->pw_dir, slash ? "/" : "", opath); + len = asprintf(&npath, "%s%s%s", pw->pw_dir, *opath ? "/" : "", opath); sudo_pw_delref(pw); if (len == -1) { sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); diff --git a/plugins/sudoers/regress/exptilde/check_exptilde.c b/plugins/sudoers/regress/exptilde/check_exptilde.c index 02d4bf087..c2054cb31 100644 --- a/plugins/sudoers/regress/exptilde/check_exptilde.c +++ b/plugins/sudoers/regress/exptilde/check_exptilde.c @@ -42,7 +42,9 @@ struct test_data { { "foo/bar", NULL, NULL, false }, { "~root", "/", NULL, true }, { "~", "/home/millert", "millert", true }, + { "~/foo", "/home/millert/foo", "millert", true }, { "~millert", "/home/millert", "millert", true }, + { "~millert/bar", "/home/millert/bar", "millert", true }, { NULL } };