cosmopolitan/test/libc/calls
Gavin Hayes 9c5a7795ad
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>
2022-10-11 21:17:50 -07:00
..
_timespec_test.c Clean up some code 2022-08-20 12:32:51 -07:00
access_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
chdir_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
clock_getres_test.c Clean up some code 2022-08-20 12:32:51 -07:00
clock_gettime_test.c Reduce build graph by another eight percent 2022-08-13 13:11:56 -07:00
closefrom_test.c Make improvements 2022-07-21 03:36:42 -07:00
commandv_test.c Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
diagnose_syscall_test.c Perform more low-level code cleanup 2022-09-09 04:07:08 -07:00
dup_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
execve_test.c vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
fcntl_test.c Add README description for new vista branch 2022-09-15 12:51:24 -07:00
fileexists_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
ftruncate_test.c Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
getcontext_test.c Perform more low-level code cleanup 2022-09-09 04:07:08 -07:00
getcwd_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
getgroups_test.c Backport main branch improvements (#658) 2022-10-10 20:44:29 -07:00
getitimer_test.c Improve ZIP filesystem and change its prefix 2021-08-22 01:11:53 -07:00
ioctl_siocgifconf_test.c Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
life.c Make improvements to locking 2022-06-19 01:30:12 -07:00
lock_test.c Fix POSIX advisory locks on Windows 2022-09-15 12:44:00 -07:00
lseek_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
mkdir_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
mkntcmdline_test.c vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
mkntenvblock_test.c Make build hermetic without shell scripts 2022-05-25 13:55:57 -07:00
mkntpath_test.c vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
nanosleep_test.c Clean up some code 2022-08-20 12:32:51 -07:00
open_test.c Make garbage collection thread safe 2022-09-08 02:33:01 -07:00
openbsd_test.c Create unit test framework for subprocesses 2022-09-03 18:02:01 -07:00
pipe_test.c Make more fixes and improvements 2022-06-13 11:02:13 -07:00
pledge2_test.c Create unit test framework for subprocesses 2022-09-03 18:02:01 -07:00
pledge_test.c vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
poll_test.c Clean up some code 2022-08-20 12:32:51 -07:00
pread_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
preadv_test.c Fix preadv() and pwritev() 2022-09-15 12:30:36 -07:00
printargs_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
ptrace_test.c Prevent Make from talking to public Internet 2022-08-12 21:51:39 -07:00
pwrite_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
raise_test.c Improve quality of raise(), abort(), and tkill() 2022-09-03 20:17:54 -07:00
read_test.c Reduce build graph by another eight percent 2022-08-13 13:11:56 -07:00
readansi_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
readlinkat_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
renameat_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
reservefd_test.c Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
sched_getaffinity_test.c Make more compatibility improvements 2022-09-06 07:04:13 -07:00
sched_setscheduler_test.c Clean up some code 2022-08-20 12:32:51 -07:00
seccomp_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
setitimer_test.c Change sigaction_f to match sysv signature (#585) 2022-09-02 05:08:35 -07:00
setrlimit_test.c Improve build latency of repository 2022-08-14 22:19:46 -07:00
sigaction_test.c Discard ignored signals on New Technology (#592) 2022-09-05 09:17:56 -07:00
signal_test.c Remove testonly keyword 2022-09-05 08:41:43 -07:00
sigpending_test.c Implement sigpending for sysv and nt (#597) 2022-09-07 05:38:12 -07:00
sigprocmask_test.c Fix inability to add some signals to mask on NT (#596) 2022-09-06 18:35:26 -07:00
sigsuspend_test.c Change sigaction_f to match sysv signature (#585) 2022-09-02 05:08:35 -07:00
stat_test.c Improve zipos path handling (#579) 2022-09-03 22:50:23 -07:00
statfs_test.c Polyfill statfs() and fstatfs() on Windows 2022-08-17 19:01:51 -07:00
symlinkat_test.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
sys_ptrace_test.c Prevent Make from talking to public Internet 2022-08-12 21:51:39 -07:00
test.mk Fix POSIX advisory locks on Windows 2022-09-15 12:44:00 -07:00
tiny64.elf Bump support up to FreeBSD 13 and NetBSD 9.2 2022-06-11 10:36:17 -07:00
tkill_test.c Get threads working on all platforms 2022-05-13 03:59:09 -07:00
unlinkat_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
unveil_test.c vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
utimensat_test.c Unbloat the build 2022-08-11 00:15:29 -07:00
vfork_test.c Remove plenty of makefile misconfigurations 2022-07-21 09:20:59 -07:00
write_test.c Reduce build graph by another eight percent 2022-08-13 13:11:56 -07:00
writev_test.c Unbloat the build 2022-08-11 00:15:29 -07:00