Mercurial > dropbear
diff dbutil.c @ 997:e75316906852 coverity
merge
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 28 Jan 2015 21:40:34 +0800 |
parents | 6fb4c010c448 |
children | 257f7d5fca97 |
line wrap: on
line diff
--- a/dbutil.c Sun Jan 04 22:33:12 2015 +0800 +++ b/dbutil.c Wed Jan 28 21:40:34 2015 +0800 @@ -936,6 +936,23 @@ } } +/* Returns malloced path. Only expands ~ in first character */ +char * expand_tilde(const char *inpath) { + struct passwd *pw = NULL; + if (inpath[0] == '~') { + pw = getpwuid(getuid()); + if (pw && pw->pw_dir) { + int len = strlen(inpath) + strlen(pw->pw_dir) + 1; + char *buf = m_malloc(len); + snprintf(buf, len, "%s/%s", pw->pw_dir, &inpath[1]); + return buf; + } + } + + /* Fallback */ + return m_strdup(inpath); +} + int constant_time_memcmp(const void* a, const void *b, size_t n) { const char *xa = a, *xb = b;