diff options
author | lum <lum@cvs.openbsd.org> | 2012-07-10 06:28:13 +0000 |
---|---|---|
committer | lum <lum@cvs.openbsd.org> | 2012-07-10 06:28:13 +0000 |
commit | 9ad429c16991131b71c7b5c90fcd4fa3f35d98ca (patch) | |
tree | 111f79209dc8a73de8edc7287c5d64488ebf8ea6 /usr.bin/mg/fileio.c | |
parent | 788b31d9696259e771e3ce9871c738955b91ab47 (diff) |
Fix an outstanding debian bug: #658539
"looks good" kjell
Diffstat (limited to 'usr.bin/mg/fileio.c')
-rw-r--r-- | usr.bin/mg/fileio.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c index 4a1c1a87892..0b63be867fc 100644 --- a/usr.bin/mg/fileio.c +++ b/usr.bin/mg/fileio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fileio.c,v 1.93 2012/06/18 07:14:55 jasper Exp $ */ +/* $OpenBSD: fileio.c,v 1.94 2012/07/10 06:28:12 lum Exp $ */ /* This file is in the public domain. */ @@ -701,7 +701,8 @@ expandtilde(const char *fn) struct passwd *pw; struct stat statbuf; const char *cp; - char user[LOGIN_NAME_MAX], path[NFILEN], *ret; + char user[LOGIN_NAME_MAX], path[NFILEN]; + char *un, *ret; size_t ulen, plen; path[0] = '\0'; @@ -720,9 +721,12 @@ expandtilde(const char *fn) return (NULL); return(ret); } - if (ulen == 0) /* ~/ or ~ */ - (void)strlcpy(user, getlogin(), sizeof(user)); - else { /* ~user/ or ~user */ + if (ulen == 0) { /* ~/ or ~ */ + if ((un = getlogin()) != NULL) + (void)strlcpy(user, un, sizeof(user)); + else + user[0] = '\0'; + } else { /* ~user/ or ~user */ memcpy(user, &fn[1], ulen); user[ulen] = '\0'; } |