Handle absolute paths properly, and don't use resolved path in

realpath() fails.
This commit is contained in:
nicm 2015-11-10 22:29:33 +00:00
parent dcdccf8333
commit 005e462e01
2 changed files with 16 additions and 8 deletions

View File

@ -77,11 +77,15 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
else
cwd = ".";
xasprintf(&file, "%s/%s", cwd, path);
if (realpath(file, resolved) == NULL)
f = NULL;
if (*path == '/')
file = xstrdup(path);
else
f = fopen(resolved, "rb");
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, "rb");
free(file);
if (f == NULL) {
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno));

View File

@ -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));