From c50bdfccdd6eed9182905a50716ee037ccb29be9 Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Sun, 27 Mar 2016 02:06:20 -0400 Subject: [PATCH] Escape sent commands --- arguments.c | 18 ++++++++++++++++-- tmate-daemon-decoder.c | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/arguments.c b/arguments.c index 16ad5110..2042a0e9 100644 --- a/arguments.c +++ b/arguments.c @@ -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); diff --git a/tmate-daemon-decoder.c b/tmate-daemon-decoder.c index c835960f..f4c8de70 100644 --- a/tmate-daemon-decoder.c +++ b/tmate-daemon-decoder.c @@ -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; }