From 005e462e01b58015f3e1d841b185186e6b5d4e14 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 10 Nov 2015 22:29:33 +0000 Subject: Handle absolute paths properly, and don't use resolved path in realpath() fails. --- cmd-save-buffer.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'cmd-save-buffer.c') 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)); -- cgit