mirror of
https://github.com/tmate-io/tmate-ssh-server.git
synced 2020-11-18 19:53:51 -08:00
Handle absolute paths properly, and don't use resolved path in
realpath() fails.
This commit is contained in:
parent
dcdccf8333
commit
005e462e01
@ -77,10 +77,14 @@ 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
|
||||
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) {
|
||||
|
@ -103,10 +103,14 @@ 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
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user