diff options
author | 2015-11-10 22:29:33 +0000 | |
---|---|---|
committer | 2015-11-10 22:29:33 +0000 | |
commit | e35bfb077a0f1f3b427153a4e7c8f08b50544f1f (patch) | |
tree | d79638a7ba060e6f0bfc848067cdfb5d580008db /usr.bin/tmux/cmd-save-buffer.c | |
parent | sync (diff) | |
download | wireguard-openbsd-e35bfb077a0f1f3b427153a4e7c8f08b50544f1f.tar.xz wireguard-openbsd-e35bfb077a0f1f3b427153a4e7c8f08b50544f1f.zip |
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)); |