summaryrefslogtreecommitdiffstats
path: root/cmd-save-buffer.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2015-11-11 08:14:36 +0000
committerThomas Adam <thomas@xteddy.org>2015-11-11 08:14:36 +0000
commit35fd6d134a84cda69730310c89846f2bacb3cfbd (patch)
treed19140d154d7149f3982e62ea77dcbcb776a4965 /cmd-save-buffer.c
parent896581628dc53556861b63f2cb4094a48f9eaf94 (diff)
parent6f3475c6c713245f5ec760298af9a04b8465b844 (diff)
Merge branch 'obsd-master'
Conflicts: utf8.c
Diffstat (limited to 'cmd-save-buffer.c')
-rw-r--r--cmd-save-buffer.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c
index 6c55fabb..87afe7ee 100644
--- a/cmd-save-buffer.c
+++ b/cmd-save-buffer.c
@@ -102,11 +102,16 @@ 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 &&
+ strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) {
+ cmdq_error(cmdq, "%s: %s", file, strerror(ENAMETOOLONG));
+ return (CMD_RETURN_ERROR);
+ }
+ f = fopen(resolved, flags);
free(file);
if (f == NULL) {
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno));