From 09571d1a6b783858019cca41ac33527b6c2cc247 Mon Sep 17 00:00:00 2001 From: Simon Nivault Date: Fri, 12 Sep 2025 14:50:03 +0200 Subject: [PATCH 1/2] Fix quote parsing --- winpr/libwinpr/thread/argv.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/winpr/libwinpr/thread/argv.c b/winpr/libwinpr/thread/argv.c index e285835e3..3a154a43c 100644 --- a/winpr/libwinpr/thread/argv.c +++ b/winpr/libwinpr/thread/argv.c @@ -244,8 +244,13 @@ LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs) if (*p != '"') WLog_ERR(TAG, "parsing error: uneven number of unescaped double quotes!"); - if (p[0] && p[1]) - p += 1 + strcspn(&p[1], " \t\0"); + if (*p) + { + p++; + + if (*p) + p += strcspn(p, " \t\0"); + } pArgs[numArgs++] = pOutput; From 38d6aa920f59a81cc3a86a037c4b916393c59854 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 12 Sep 2025 19:44:17 +0200 Subject: [PATCH 2/2] [winpr,thread] add unit test case --- winpr/libwinpr/thread/test/TestThreadCommandLineToArgv.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/winpr/libwinpr/thread/test/TestThreadCommandLineToArgv.c b/winpr/libwinpr/thread/test/TestThreadCommandLineToArgv.c index 91017b898..80941bf74 100644 --- a/winpr/libwinpr/thread/test/TestThreadCommandLineToArgv.c +++ b/winpr/libwinpr/thread/test/TestThreadCommandLineToArgv.c @@ -31,6 +31,10 @@ static const char* test_args_line_7 = "app.exe a\\\\\\\\\"b c\" d e f\\\\\\\\\"g static const char* test_args_list_7[] = { "app.exe", "a\\\\b c", "d", "e", "f\\\\g h", "i", "j" }; +static const char* test_args_line_8 = "app.exe arg1 \"arg2\""; + +static const char* test_args_list_8[] = { "app.exe", "arg1", "arg2" }; + static BOOL test_command_line_parsing_case(const char* line, const char** list, size_t expect) { BOOL rc = FALSE; @@ -104,6 +108,9 @@ int TestThreadCommandLineToArgv(int argc, char* argv[]) if (!test_command_line_parsing_case(test_args_line_7, test_args_list_7, ARRAYSIZE(test_args_list_7))) return -1; + if (!test_command_line_parsing_case(test_args_line_8, test_args_list_8, + ARRAYSIZE(test_args_list_8))) + return -1; return 0; }