diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-11-10 22:29:34 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-11-10 22:29:34 +0000 |
commit | 202ae6648f03f943d96f2cd8416448ede0efdb9d (patch) | |
tree | 4f1c8d6192edae20f5123bcbc1f568e49d73b2b4 /usr.bin/tmux/cmd-save-buffer.c | |
parent | 4dbf3d9cbdbf6bd34900dd32e425eee52857f18a (diff) |
Handle absolute paths properly, and don't use resolved path in
realpath() fails.
Diffstat (limited to 'usr.bin/tmux/cmd-save-buffer.c')
-rw-r--r-- | usr.bin/tmux/cmd-save-buffer.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/usr.bin/tmux/cmd-save-buffer.c b/usr.bin/tmux/cmd-save-buffer.c index b85a16bdb63..f61fb92f61c 100644 --- a/usr.bin/tmux/cmd-save-buffer.c +++ b/usr.bin/tmux/cmd-save-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-save-buffer.c,v 1.31 2015/10/31 08:13:58 nicm Exp $ */ +/* $OpenBSD: cmd-save-buffer.c,v 1.32 2015/11/10 22:29:33 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -103,11 +103,15 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(self->args, 'a')) flags = "ab"; - xasprintf(&file, "%s/%s", cwd, path); - if (realpath(file, resolved) == NULL) - f = NULL; + if (*path == '/') + file = xstrdup(path); else - f = fopen(resolved, flags); + xasprintf(&file, "%s/%s", cwd, path); + if (realpath(file, resolved) == NULL) { + cmdq_error(cmdq, "%s: %s", file, strerror(errno)); + return (CMD_RETURN_ERROR); + } + f = fopen(resolved, flags); free(file); if (f == NULL) { cmdq_error(cmdq, "%s: %s", resolved, strerror(errno)); |