Re:Why Does Windows Use Backslash as Path Separator?
by asveikau on Thursday April 25, 2024 @11:25AM
(#40158678)
Here's an example of someone citing a disagreement between CRT and shell32:
https://github.com/rust-lang/rust/issues/44650
This in addition to the Rust CVE mentioned elsewhere in the thread which was rooted in this issue:
https://blog.rust-lang.org/2024/04/09/cve-2024-24576.html
Here are some quick programs to test contrasting approaches. I don't have examples of inputs where they parse differently on hand right now, but I know they exist. This was also a problem that was frequently discussed internally when I worked at MSFT.
#include <stdio.h>
int main(int argc, char **argv)
{
for (int i=0; i<argc; ++i)
puts(argv[i]);
return 0;
}
#pragma comment(lib, "shell32.lib")
#include <windows.h>
#include <stdio.h>
int main()
{
PCWSTR cmdLine = GetCommandLineW();
if (cmdLine)
{
int argc = 0;
PWSTR *argv = CommandLineToArgvW(cmdLine, &argc);
if (argv)
{
for (int i=0; i<argc; ++i)
printf("%ls\n", argv[i]);
LocalFree(argv);
return 0;
}
}
return 1;
}
I picked the first MSFT page on argv, https://learn.microsoft.com/en-us/cpp/c-language/parsing-c-c... and compiled and ran that program with various command lines, and it does exactly what I expected (argv array members are tokenized according to my quoting).
Could you be clearer, perhaps by posting a simple C example and a few command lines demonstrating what you mean?