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; 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; }