From 976b08312ba9a5482f672efdd8c0d3cc3d9b9782 Mon Sep 17 00:00:00 2001 From: Heiko Hund Date: Tue, 16 Oct 2012 18:54:54 +0200 Subject: [PATCH] escape \ and " in user input to management itf --- misc.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/misc.c b/misc.c index 9ca2617..1d545cf 100644 --- a/misc.c +++ b/misc.c @@ -83,10 +83,26 @@ ManagementCommandFromInput(connection_t *c, LPCSTR fmt, HWND hDlg, int id) { BOOL retval = FALSE; LPSTR input, cmd; - int input_len, cmd_len; + int input_len, cmd_len, pos; GetDlgItemTextUtf8(hDlg, id, &input, &input_len); + /* Escape input if needed */ + for (pos = 0; pos < input_len; ++pos) + { + if (input[pos] == '\\' || input[pos] == '"') + { + LPSTR buf = realloc(input, ++input_len + 1); + if (buf == NULL) + goto out; + + input = buf; + memmove(input + pos + 1, input + pos, input_len - pos + 1); + input[pos] = '\\'; + pos += 1; + } + } + cmd_len = input_len + strlen(fmt); cmd = malloc(cmd_len); if (cmd) @@ -96,10 +112,11 @@ ManagementCommandFromInput(connection_t *c, LPCSTR fmt, HWND hDlg, int id) free(cmd); } +out: /* Clear buffers with potentially secret content */ if (input_len) { - memset(input, 'x', input_len - 1); + memset(input, 'x', input_len); SetDlgItemTextA(hDlg, id, input); free(input); }