Improve command line parsing

Instead of allowing only one quote at the beginning and one at the end
of the command name, now we're reading the command line character by
character, also advancing in the CRT-parsed command name and skipping
any number of quotes.

As far as I can tell, there is no other hole in it, but just to be sure,
any parsing failure is now fatal.
This commit is contained in:
David Macek 2021-04-04 11:50:42 +02:00
parent 49787dc7b0
commit 1817f53cae
2 changed files with 15 additions and 5 deletions

View File

@ -11,7 +11,7 @@ conflicts=("${_realname}")
depends=("mintty>=2.2.1") depends=("mintty>=2.2.1")
makedepends=('mingw-w64-cross-gcc') makedepends=('mingw-w64-cross-gcc')
source=(launcher.{c,ini,rc} {macros,version}.h Makefile {msys2,mingw32,mingw64,ucrt64,clang64}.ico) source=(launcher.{c,ini,rc} {macros,version}.h Makefile {msys2,mingw32,mingw64,ucrt64,clang64}.ico)
sha512sums=('e1137164c4ba8f49a9d9a3a83a7f45cb2121440b958ee610a666ee421b70a17fc0767a88a8502d9ae0f11fa004d7c050b44e53e1395048cf3c41104c27dda137' sha512sums=('ed2937084cc7d176bb9f06af96121dbf4433a05cfc8fa260918a5f96ed5e8c4201fa2b45aa196a858ece0c8a86f7ffc617a8330b57b7231a4ea4ab23d75920b0'
'5ed8a2e9997d9d2c1e17940292d68542f897e2716b274741d8a3ba7c8f46235c175b7e0a1252a879ba3c79b571504d25de2a8d6b004aedd117d263195bc2b185' '5ed8a2e9997d9d2c1e17940292d68542f897e2716b274741d8a3ba7c8f46235c175b7e0a1252a879ba3c79b571504d25de2a8d6b004aedd117d263195bc2b185'
'cf257f1f5b7fc69a32c63fe5bf5299db078621850b1e12358654d71da7777a94a0668d657c1834be308db099cad9d48a42fa7877ad58dfdbd576248150913a12' 'cf257f1f5b7fc69a32c63fe5bf5299db078621850b1e12358654d71da7777a94a0668d657c1834be308db099cad9d48a42fa7877ad58dfdbd576248150913a12'
'6019ca0d67375c1261dda0d54d45fc411b02244c51b71d5c57d2613e9edfb4e8f9000754e5c7d632ed0101005c01cd0a98c3961d5b5f51c94d83eceba4296d35' '6019ca0d67375c1261dda0d54d45fc411b02244c51b71d5c57d2613e9edfb4e8f9000754e5c7d632ed0101005c01cd0a98c3961d5b5f51c94d83eceba4296d35'

View File

@ -235,13 +235,23 @@ int wmain(int argc, wchar_t* argv[]) {
ShowLastError(L"Could not set environment variable"); ShowLastError(L"Could not set environment variable");
} }
// can break, but hopefully won't for most use cases
args = GetCommandLine(); args = GetCommandLine();
if (args[0] == L'"') { tmp = argv[0];
while (*tmp != L'\0') {
if (*args == *tmp) {
args++;
tmp++;
} else if (*args == L'"') {
args++;
} else {
ShowError(L"Could not parse command name", argv[0], 0);
return __LINE__;
}
}
while (*args == L'"') {
args++; args++;
} }
args += wcslen(argv[0]); while (*args == L' ') {
if (args[0] == L'"') {
args++; args++;
} }