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,11 +77,15 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
|
|||||||
else
|
else
|
||||||
cwd = ".";
|
cwd = ".";
|
||||||
|
|
||||||
xasprintf(&file, "%s/%s", cwd, path);
|
if (*path == '/')
|
||||||
if (realpath(file, resolved) == NULL)
|
file = xstrdup(path);
|
||||||
f = NULL;
|
|
||||||
else
|
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);
|
free(file);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno));
|
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'))
|
if (args_has(self->args, 'a'))
|
||||||
flags = "ab";
|
flags = "ab";
|
||||||
|
|
||||||
xasprintf(&file, "%s/%s", cwd, path);
|
if (*path == '/')
|
||||||
if (realpath(file, resolved) == NULL)
|
file = xstrdup(path);
|
||||||
f = NULL;
|
|
||||||
else
|
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);
|
free(file);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno));
|
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user