From 8f5639a9bd42def63f6066a1a8d6a2efd669fad8 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sat, 30 May 2026 16:29:53 +0200 Subject: [PATCH] [NETSH] Remove quotation marks from quoted arguments Add support for quoted strings to the script file interpreter. --- base/applications/network/netsh/interpreter.c | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/base/applications/network/netsh/interpreter.c b/base/applications/network/netsh/interpreter.c index 67c2adf03a2..abbb7eecc05 100644 --- a/base/applications/network/netsh/interpreter.c +++ b/base/applications/network/netsh/interpreter.c @@ -334,17 +334,21 @@ InterpretLine( _In_ LPWSTR pszInputLine) { LPWSTR args_vector[MAX_ARGS_COUNT]; - DWORD dwArgCount = 0; + DWORD dwArgCount = 0, i, len; BOOL bWhiteSpace = TRUE; BOOL bDone = FALSE; - LPWSTR ptr; + BOOL bInQuotes = FALSE; + LPWSTR ptr, pStartQuote, pEndQuote; memset(args_vector, 0, sizeof(args_vector)); ptr = pszInputLine; while (*ptr != 0) { - if (iswspace(*ptr) || *ptr == L'\n') + if (*ptr == L'\"') + bInQuotes = (bInQuotes) ? FALSE : TRUE; + + if ((iswspace(*ptr) && (bInQuotes == FALSE)) || *ptr == L'\n') { *ptr = 0; bWhiteSpace = TRUE; @@ -363,6 +367,22 @@ InterpretLine( ptr++; } + /* Remove quotation marks */ + for (i = 0; i < dwArgCount; i++) + { + pStartQuote = wcschr(args_vector[i], L'\"'); + if (pStartQuote) + { + pEndQuote = wcschr(pStartQuote + 1, L'\"'); + if (pEndQuote) + { + len = pEndQuote - pStartQuote; + memmove(pStartQuote, pStartQuote + 1, (len - 1) * sizeof(WCHAR)); + *(pEndQuote - 1) = UNICODE_NULL; + } + } + } + return InterpretCommand(args_vector, dwArgCount, &bDone); } @@ -386,11 +406,11 @@ InterpretInteractive(VOID) { WCHAR input_line[MAX_STRING_SIZE]; LPWSTR args_vector[MAX_ARGS_COUNT]; - DWORD dwArgCount = 0; + DWORD dwArgCount = 0, i, len; BOOL bWhiteSpace = TRUE; BOOL bDone = FALSE; BOOL bInQuotes = FALSE; - LPWSTR ptr; + LPWSTR ptr, pStartQuote, pEndQuote; DWORD dwError = ERROR_SUCCESS; for (;;) @@ -415,7 +435,7 @@ InterpretInteractive(VOID) if ((iswspace(*ptr) && (bInQuotes == FALSE)) || *ptr == L'\n') { - *ptr = 0; + *ptr = UNICODE_NULL; bWhiteSpace = TRUE; } else @@ -430,6 +450,22 @@ InterpretInteractive(VOID) ptr++; } + /* Remove quotation marks */ + for (i = 0; i < dwArgCount; i++) + { + pStartQuote = wcschr(args_vector[i], L'\"'); + if (pStartQuote) + { + pEndQuote = wcschr(pStartQuote + 1, L'\"'); + if (pEndQuote) + { + len = pEndQuote - pStartQuote; + memmove(pStartQuote, pStartQuote + 1, (len - 1) * sizeof(WCHAR)); + *(pEndQuote - 1) = UNICODE_NULL; + } + } + } + dwError = InterpretCommand(args_vector, dwArgCount, &bDone); if ((dwError != ERROR_SUCCESS) && (dwError != ERROR_SUPPRESS_OUTPUT)) {