diff options
author | nicm <nicm> | 2015-11-10 22:29:33 +0000 |
---|---|---|
committer | nicm <nicm> | 2015-11-10 22:29:33 +0000 |
commit | 005e462e01b58015f3e1d841b185186e6b5d4e14 (patch) | |
tree | 04f7d6b9887f73b143333083452e510aab09d448 /cmd-save-buffer.c | |
parent | dcdccf83338654e41281b3b4a8f1c8d2e0621a13 (diff) | |
download | rtmux-005e462e01b58015f3e1d841b185186e6b5d4e14.tar.gz rtmux-005e462e01b58015f3e1d841b185186e6b5d4e14.tar.bz2 rtmux-005e462e01b58015f3e1d841b185186e6b5d4e14.zip |
Handle absolute paths properly, and don't use resolved path in
realpath() fails.
Diffstat (limited to 'cmd-save-buffer.c')
-rw-r--r-- | cmd-save-buffer.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c index dca2c8ef..8de99075 100644 --- a/cmd-save-buffer.c +++ b/cmd-save-buffer.c @@ -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)); |