mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Handle absolute paths properly, and don't use resolved path in
realpath() fails.
This commit is contained in:
parent
dcdccf8333
commit
005e462e01
@ -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));
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user