Fix tilde expansion of paths with no user like ~/foo.

The '/' separator was missing in the resulting path.
This commit is contained in:
Todd C. Miller
2021-02-16 13:19:58 -07:00
parent a18b2a9ddf
commit 5ec59cddc2
2 changed files with 3 additions and 1 deletions

View File

@@ -86,7 +86,7 @@ expand_tilde(char **path, const char *user)
debug_return_bool(false); 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); sudo_pw_delref(pw);
if (len == -1) { if (len == -1) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));

View File

@@ -42,7 +42,9 @@ struct test_data {
{ "foo/bar", NULL, NULL, false }, { "foo/bar", NULL, NULL, false },
{ "~root", "/", NULL, true }, { "~root", "/", NULL, true },
{ "~", "/home/millert", "millert", true }, { "~", "/home/millert", "millert", true },
{ "~/foo", "/home/millert/foo", "millert", true },
{ "~millert", "/home/millert", "millert", true }, { "~millert", "/home/millert", "millert", true },
{ "~millert/bar", "/home/millert/bar", "millert", true },
{ NULL } { NULL }
}; };