Commit 3c1abee4 authored by Stas Korobeynikov's avatar Stas Korobeynikov Committed by Pavel Vainerman

fix tildeexpand path

parent 696222ce
...@@ -609,7 +609,7 @@ char * ...@@ -609,7 +609,7 @@ char *
tilde_expand_filename(const char *filename, uid_t uid) tilde_expand_filename(const char *filename, uid_t uid)
{ {
const char *path, *sep; const char *path, *sep;
char user[128], *ret; char user[128], *ret, *pwpath;
struct passwd *pw; struct passwd *pw;
u_int len, slash; u_int len, slash;
...@@ -629,31 +629,19 @@ tilde_expand_filename(const char *filename, uid_t uid) ...@@ -629,31 +629,19 @@ tilde_expand_filename(const char *filename, uid_t uid)
} else if ((pw = getpwuid(uid)) == NULL) /* ~/path */ } else if ((pw = getpwuid(uid)) == NULL) /* ~/path */
fatal("tilde_expand_filename: No such uid %ld", (long)uid); fatal("tilde_expand_filename: No such uid %ld", (long)uid);
if(options.home) pwpath = options.home ? options.home : pw->pw_dir;
{
if (strlcpy(ret, options.home, sizeof(ret)) >= sizeof(ret))
fatal("tilde_expand_filename: Path too long");
/* Make sure directory has a trailing '/' */ /* Make sure directory has a trailing '/' */
len = strlen(options.home); len = strlen(pwpath);
if ((len == 0 || options.home[len - 1] != '/') && if (len == 0 || pwpath[len - 1] != '/')
strlcat(ret, "/", sizeof(ret)) >= sizeof(ret)) sep = "/";
fatal("tilde_expand_filename: Path too long"); else
} sep = "";
else
{
/* Make sure directory has a trailing '/' */
len = strlen(pw->pw_dir);
if (len == 0 || pw->pw_dir[len - 1] != '/')
sep = "/";
else
sep = "";
}
/* Skip leading '/' from specified path */ /* Skip leading '/' from specified path */
if (path != NULL) if (path != NULL)
filename = path + 1; filename = path + 1;
if (xasprintf(&ret, "%s%s%s", pw->pw_dir, sep, filename) >= PATH_MAX) if (xasprintf(&ret, "%s%s%s", pwpath, sep, filename) >= PATH_MAX)
fatal("tilde_expand_filename: Path too long"); fatal("tilde_expand_filename: Path too long");
return (ret); return (ret);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment