Mercurial > dropbear
diff dbutil.c @ 1924:667937351c31
Fix tilde expansion of paths
(Part was missed from previous series of commits)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 30 Mar 2022 14:08:15 +0800 |
parents | 9382271da9ef |
children | 7ac3b6c380b1 |
line wrap: on
line diff
--- a/dbutil.c Thu Jul 09 22:06:26 2020 +1000 +++ b/dbutil.c Wed Mar 30 14:08:15 2022 +0800 @@ -633,11 +633,11 @@ } } -/* Returns malloced path. inpath beginning with '/' is returned as-is, -otherwise home directory is prepended */ +/* Returns malloced path. inpath beginning with '~/' expanded, + otherwise returned as-is */ char * expand_homedir_path(const char *inpath) { struct passwd *pw = NULL; - if (inpath[0] != '/') { + if (strncmp(inpath, "~/", 2) == 0) { char *homedir = getenv("HOME"); if (!homedir) { @@ -648,9 +648,9 @@ } if (homedir) { - int len = strlen(inpath) + strlen(homedir) + 2; + int len = strlen(inpath)-2 + strlen(homedir) + 2; char *buf = m_malloc(len); - snprintf(buf, len, "%s/%s", homedir, inpath); + snprintf(buf, len, "%s/%s", homedir, inpath+2); return buf; } }