mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 16:28:30 +00:00
vista: backport execve escaping and using cocmd as shell for system, etc. (#660)
* Introduce testlib_extract() helper * Have execve() escape double quotes in cmd.exe's preferred style This makes it possible for us to use system() and popen() with paths that redirect to filenames that contain spaces, e.g. system("echo.com hello >\"hello there.txt\"") It's difficult to solve this problem, because WIN32 only allows passing one single argument when launching programs and each program is allowed to tokenize that however it wants. Most software follows the convention of cmd.exe which is poorly documented and positively byzantine. In the future we're going to solve this by not using cmd.exe at all and instead embedding the cocmd.com interpreter into the system() function. In the meantime, our documentation has been updated to help recalibrate any expectation the user might hold regarding the security of using the Windows command interpreter. Fixes #644 * Introduce double quote support in cocmd.com shell * Add some tests for execve() * Embed cocmd.com interpreter for system() / open() This change lets you use system() in an easier and portable way. The problem with the call in the past has always been that bourne and cmd.com on Windows have less than nothing in common, so pretty much the only command system() could be used for across platforms was maybe echo. cmd.exe is also a security liability due to its escaping rules. Since cocmd.com implements 85% of what we need from bourne, in a really tiny way, it makes perfect sense to be embedded in these functionss. We get a huge performance boost too. Fixes #644 * Support whitespace after cocmd output redirection Co-authored-by: Justine Tunney <jtunney@gmail.com>
This commit is contained in:
parent
f4ff1729d1
commit
9c5a7795ad
28 changed files with 622 additions and 401 deletions
|
@ -173,5 +173,24 @@ textwindows int __mkntpath2(const char *path,
|
|||
p[j] = 0;
|
||||
n = j;
|
||||
|
||||
return x + m + n;
|
||||
// our path is now stored at `path16` with length `n`
|
||||
n = x + m + n;
|
||||
|
||||
// To avoid toil like this:
|
||||
//
|
||||
// CMD.EXE was started with the above path as the current directory.
|
||||
// UNC paths are not supported. Defaulting to Windows directory.
|
||||
// Access is denied.
|
||||
//
|
||||
// Remove \\?\ prefix if we're within 260 character limit.
|
||||
if (n > 4 && n < 260 && //
|
||||
path16[0] == '\\' && //
|
||||
path16[1] == '\\' && //
|
||||
path16[2] == '?' && //
|
||||
path16[3] == '\\') {
|
||||
memmove(path16, path16 + 4, (n - 4 + 1) * sizeof(char16_t));
|
||||
n -= 4;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue