| ... | ... | @@ -1479,6 +1479,8 @@ const WindowsCommandLineCache = struct { |
| 1479 | 1479 | } |
| 1480 | 1480 | }; |
| 1481 | 1481 | |
| 1482 | /// Returns the absolute path of `cmd.exe` within the Windows system directory. |
| 1483 | /// The caller owns the returned slice. |
| 1482 | 1484 | fn windowsCmdExePath(allocator: mem.Allocator) error{ OutOfMemory, Unexpected }![:0]u16 { |
| 1483 | 1485 | var buf = try std.ArrayListUnmanaged(u16).initCapacity(allocator, 128); |
| 1484 | 1486 | errdefer buf.deinit(allocator); |
| ... | ... | @@ -1510,6 +1512,11 @@ const ArgvToCommandLineError = error{ OutOfMemory, InvalidWtf8, InvalidArg0 }; |
| 1510 | 1512 | |
| 1511 | 1513 | /// Serializes `argv` to a Windows command-line string suitable for passing to a child process and |
| 1512 | 1514 | /// parsing by the `CommandLineToArgvW` algorithm. The caller owns the returned slice. |
| 1515 | /// |
| 1516 | /// To avoid arbitrary command execution, this function should not be used when spawning `.bat`/`.cmd` scripts. |
| 1517 | /// https://flatt.tech/research/posts/batbadbut-you-cant-securely-execute-commands-on-windows/ |
| 1518 | /// |
| 1519 | /// When executing `.bat`/`.cmd` scripts, use `argvToScriptCommandLineWindows` instead. |
| 1513 | 1520 | fn argvToCommandLineWindows( |
| 1514 | 1521 | allocator: mem.Allocator, |
| 1515 | 1522 | argv: []const []const u8, |
| ... | ... | @@ -1678,6 +1685,14 @@ const ArgvToScriptCommandLineError = error{ |
| 1678 | 1685 | /// |
| 1679 | 1686 | /// Escapes `argv` using the suggested mitigation against arbitrary command execution from: |
| 1680 | 1687 | /// https://flatt.tech/research/posts/batbadbut-you-cant-securely-execute-commands-on-windows/ |
| 1688 | /// |
| 1689 | /// The return of this function will look like |
| 1690 | /// `cmd.exe /d /e:ON /v:OFF /c "<escaped command line>"` |
| 1691 | /// and should be used as the `lpCommandLine` of `CreateProcessW`, while the |
| 1692 | /// return of `windowsCmdExePath` should be used as `lpApplicationName`. |
| 1693 | /// |
| 1694 | /// Should only be used when spawning `.bat`/`.cmd` scripts, see `argvToCommandLineWindows` otherwise. |
| 1695 | /// The `.bat`/`.cmd` file must be known to both have the `.bat`/`.cmd` extension and exist on the filesystem. |
| 1681 | 1696 | fn argvToScriptCommandLineWindows( |
| 1682 | 1697 | allocator: mem.Allocator, |
| 1683 | 1698 | /// Path to the `.bat`/`.cmd` script. If this path is relative, it is assumed to be relative to the CWD. |