From 5d77a13799e57faf55a94cfb0dd385fccbda6c4e Mon Sep 17 00:00:00 2001 From: "Chris West (Faux)" Date: Mon, 27 Jun 2016 12:19:22 +0000 Subject: [PATCH] #249: don't truncate command line arguments to the length of the stored cygcmd --- windows/window.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/windows/window.c b/windows/window.c index 38f36422c..178b1a843 100644 --- a/windows/window.c +++ b/windows/window.c @@ -717,14 +717,18 @@ int putty_main(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) /* Concatenate all the remaining arguments separating * them with spaces to get the command line to execute. */ - char *p = conf_get_str(conf, CONF_cygcmd); - char *const end = conf_get_str(conf, CONF_cygcmd) + strlen(conf_get_str(conf, CONF_cygcmd)); - for (; i < argc && p < end; i++) { - p = stpcpy_max(p, argv[i], end - p - 1); + const size_t max_len = 0x10000; + char *buf = malloc(max_len); + char *p = buf; + char *end = p + max_len; + p = stpcpy_max(p, conf_get_str(conf, CONF_cygcmd), max_len - 1); + for (; i < argc && (p - buf) < max_len; i++) { + p = stpcpy_max(p, argv[i], max_len - 1); *p++ = ' '; } - assert(p > conf_get_str(conf, CONF_cygcmd) && p <= end); *--p = '\0'; + conf_set_str(conf, CONF_cygcmd, buf); + free(buf); got_host = 1; } else { /*