1
0
mirror of https://github.com/tmate-io/tmate-ssh-server.git synced 2020-11-18 19:53:51 -08:00

Escape sent commands

This commit is contained in:
Nicolas Viennot 2016-03-27 02:06:20 -04:00
parent 1992c67254
commit c50bdfccdd
2 changed files with 17 additions and 2 deletions

View File

@ -177,20 +177,34 @@ args_print(struct args *args)
args_print_add(&buf, &len, " -%c ", entry->flag);
else
args_print_add(&buf, &len, "-%c ", entry->flag);
if (strchr(entry->value, ' ') != NULL)
#ifdef TMATE_SLAVE
if (strchr(entry->value, '\'') != NULL)
args_print_add(&buf, &len, "\"%s\"", entry->value);
else
args_print_add(&buf, &len, "%s", entry->value);
args_print_add(&buf, &len, "'%s'", entry->value);
#else
if (strchr(entry->value, '\'') != NULL)
args_print_add(&buf, &len, "\"%s\"", entry->value);
else
args_print_add(&buf, &len, "'%s'", entry->value);
#endif
}
/* And finally the argument vector. */
for (i = 0; i < args->argc; i++) {
if (*buf != '\0')
args_print_add(&buf, &len, " ");
#ifdef TMATE_SLAVE
if (strchr(args->argv[i], '\'') != NULL)
args_print_add(&buf, &len, "\"%s\"", args->argv[i]);
else
args_print_add(&buf, &len, "'%s'", args->argv[i]);
#else
if (strchr(args->argv[i], ' ') != NULL)
args_print_add(&buf, &len, "\"%s\"", args->argv[i]);
else
args_print_add(&buf, &len, "%s", args->argv[i]);
#endif
}
return (buf);

View File

@ -213,6 +213,7 @@ static void tmate_exec_cmd(__unused struct tmate_session *session,
tmate_info("Local cmd: %s", cmd_str);
if (cmd_string_parse(cmd_str, &cmdlist, NULL, 0, &cause) != 0) {
tmate_info("parse error: %s", cause);
free(cause);
goto out;
}