@@ -1934,6 +1934,8 @@ pub const WindowsCommandLineCache = struct {
1934
1934
}
1935
1935
};
1936
1936
1937
+ /// Returns the absolute path of `cmd.exe` within the Windows system directory.
1938
+ /// The caller owns the returned slice.
1937
1939
pub fn windowsCmdExePath (allocator : mem.Allocator ) error { OutOfMemory , Unexpected }! [:0 ]u16 {
1938
1940
var buf = try std .ArrayListUnmanaged (u16 ).initCapacity (allocator , 128 );
1939
1941
errdefer buf .deinit (allocator );
@@ -1965,6 +1967,11 @@ pub const ArgvToCommandLineError = error{ OutOfMemory, InvalidWtf8, InvalidArg0
1965
1967
1966
1968
/// Serializes `argv` to a Windows command-line string suitable for passing to a child process and
1967
1969
/// parsing by the `CommandLineToArgvW` algorithm. The caller owns the returned slice.
1970
+ ///
1971
+ /// To avoid arbitrary command execution, this function should not be used when spawning `.bat`/`.cmd` scripts.
1972
+ /// https://flatt.tech/research/posts/batbadbut-you-cant-securely-execute-commands-on-windows/
1973
+ ///
1974
+ /// When executing `.bat`/`.cmd` scripts, use `argvToScriptCommandLineWindows` instead.
1968
1975
pub fn argvToCommandLineWindows (
1969
1976
allocator : mem.Allocator ,
1970
1977
argv : []const []const u8 ,
@@ -2133,6 +2140,14 @@ pub const ArgvToScriptCommandLineError = error{
2133
2140
///
2134
2141
/// Escapes `argv` using the suggested mitigation against arbitrary command execution from:
2135
2142
/// https://flatt.tech/research/posts/batbadbut-you-cant-securely-execute-commands-on-windows/
2143
+ ///
2144
+ /// The return of this function will look like
2145
+ /// `cmd.exe /d /e:ON /v:OFF /c "<escaped command line>"`
2146
+ /// and should be used as the `lpCommandLine` of `CreateProcessW`, while the
2147
+ /// return of `windowsCmdExePath` should be used as `lpApplicationName`.
2148
+ ///
2149
+ /// Should only be used when spawning `.bat`/`.cmd` scripts, see `argvToCommandLineWindows` otherwise.
2150
+ /// The `.bat`/`.cmd` file must be known to both have the `.bat`/`.cmd` extension and exist on the filesystem.
2136
2151
pub fn argvToScriptCommandLineWindows (
2137
2152
allocator : mem.Allocator ,
2138
2153
/// Path to the `.bat`/`.cmd` script. If this path is relative, it is assumed to be relative to the CWD.
0 commit comments