summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2013-10-10 12:14:10 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2013-10-10 12:14:10 +0000
commit92c661700f1f33017b9137081f422afbfbcf1371 (patch)
treef0ffd4523eb2f696cec99f0afc736135e69d7112 /usr.bin/tmux
parentdf65d81947e08c6ffecc0f31bae0a40aa618b786 (diff)
Make tilde expansion in command strings work even if it isn't terminated by /.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-string.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-string.c b/usr.bin/tmux/cmd-string.c
index 8e5d549f84b..9a817a7c8e0 100644
--- a/usr.bin/tmux/cmd-string.c
+++ b/usr.bin/tmux/cmd-string.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-string.c,v 1.18 2013/03/24 09:54:10 nicm Exp $ */
+/* $OpenBSD: cmd-string.c,v 1.19 2013/10/10 12:14:09 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -318,10 +318,13 @@ cmd_string_expand_tilde(const char *s, size_t *p)
{
struct passwd *pw;
struct environ_entry *envent;
- char *home, *path, *username;
+ char *home, *path, *user, *cp;
+ int last;
home = NULL;
- if (cmd_string_getc(s, p) == '/') {
+
+ last = cmd_string_getc(s, p);
+ if (last == EOF || last == '/' || last == ' '|| last == '\t') {
envent = environ_find(&global_environ, "HOME");
if (envent != NULL && *envent->value != '\0')
home = envent->value;
@@ -329,15 +332,27 @@ cmd_string_expand_tilde(const char *s, size_t *p)
home = pw->pw_dir;
} else {
cmd_string_ungetc(p);
- if ((username = cmd_string_string(s, p, '/', 0)) == NULL)
- return (NULL);
- if ((pw = getpwnam(username)) != NULL)
+
+ cp = user = xmalloc(strlen(s));
+ for (;;) {
+ last = cmd_string_getc(s, p);
+ if (last == EOF || last == '/' || last == ' '|| last == '\t')
+ break;
+ *cp++ = last;
+ }
+ *cp = '\0';
+
+ if ((pw = getpwnam(user)) != NULL)
home = pw->pw_dir;
- free(username);
+ free(user);
}
+
if (home == NULL)
return (NULL);
- xasprintf(&path, "%s/", home);
+ if (last != EOF)
+ xasprintf(&path, "%s%c", home, last);
+ else
+ xasprintf(&path, "%s", home);
return (path);
}