cosmopolitan/libc/stdio
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
..
__fpurge.c Add more missing libc functionality 2022-08-06 10:50:51 -07:00
append.internal.h Add Linux ptrace() tutorial 2022-03-24 08:00:36 -07:00
appendd.c Restart CI for New Technology and UBSAN hunting 2022-03-21 04:32:57 -07:00
appendf.c Add function for creating hex string literals 2021-08-07 07:05:19 -07:00
appendr.c Correct more typos (#500) 2022-07-21 20:53:30 -07:00
appends.c Add function for creating hex string literals 2021-08-07 07:05:19 -07:00
appendstrlist.c Simplify redbean serialization code 2022-09-06 20:07:29 -07:00
appendw.c Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
appendz.c Add function for creating hex string literals 2021-08-07 07:05:19 -07:00
big5.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
clearerr.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
clearerr_unlocked.c Make improvements 2022-05-28 00:28:09 -07:00
cocmd.c vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
cocmd.internal.h vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
codepages.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
ctermid.c Add ctermid and L_ctermid 2022-07-22 04:39:04 -07:00
dirstream.c Backport main branch improvements (#658) 2022-10-10 20:44:29 -07:00
dtoa.c Fix stdio fmt of "%.0e" and "%.0g" (#544) 2022-08-18 15:53:07 -07:00
dumphexc.c Unbloat the build 2022-08-11 00:15:29 -07:00
ecvt.c Don't relocate file descriptor memory 2022-09-09 16:54:28 -07:00
fbufsize.c Work towards improving signals and processes 2021-01-27 19:34:02 -08:00
fclose.c Fix some issues and do some code cleanup 2022-05-23 10:15:53 -07:00
fclose_s.c Improve locks and signals 2022-04-12 05:20:17 -07:00
fdopen.c Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
feof.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
feof_unlocked.c Make improvements 2022-05-28 00:28:09 -07:00
ferror.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
ferror_unlocked.c Make improvements 2022-05-28 00:28:09 -07:00
fflush.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fflush.internal.h Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fflush_unlocked.c Tidy up the threading implementation 2022-09-10 02:56:25 -07:00
fflushimpl.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
fgetc.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fgetc_unlocked.c Make improvements 2022-05-28 00:28:09 -07:00
fgetln.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fgetpos.c Change license 2020-12-27 17:18:44 -08:00
fgets.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fgets_unlocked.c Clean up some code 2022-08-20 12:32:51 -07:00
fgetwc.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fgetwc_unlocked.c Make improvements 2022-05-28 00:28:09 -07:00
fgetws.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fgetws_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
fileno.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fileno_unlocked.c Refactor some code 2022-05-28 14:09:21 -07:00
flbf.c Work towards improving signals and processes 2021-01-27 19:34:02 -08:00
flockfile.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
flushers.c Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
flushlbf.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fmemopen.c Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
fopen.c Restore zip.com and .symtab files 2022-08-21 00:17:20 -07:00
fopenflags.c Fix issues with stdio needed for Lua 2021-03-06 19:04:26 -08:00
fpending.c Work towards improving signals and processes 2021-01-27 19:34:02 -08:00
fprintf.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fprintf_unlocked.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
fpurge.c Add more missing libc functionality 2022-08-06 10:50:51 -07:00
fputc.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fputc_unlocked.c Refactor some code 2022-05-28 14:09:21 -07:00
fputs.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fputs_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
fputwc.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fputwc_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
fputws.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fputws_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
fread.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fread_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
freadable.c Work towards improving signals and processes 2021-01-27 19:34:02 -08:00
freading.c Work towards improving signals and processes 2021-01-27 19:34:02 -08:00
freestrlist.c Simplify redbean serialization code 2022-09-06 20:07:29 -07:00
freopen.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fscanf.c Change license 2020-12-27 17:18:44 -08:00
fseek.c Make major improvements to stdio 2021-03-26 22:31:41 -07:00
fseeko.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fseeko_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
fsetlocking.c Add raw memory visualization tool to redbean 2022-05-14 04:33:58 -07:00
fsetpos.c Change license 2020-12-27 17:18:44 -08:00
ftell.c Make major improvements to stdio 2021-03-26 22:31:41 -07:00
ftello.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
ftrylockfile.c Apply even more fixups 2022-06-12 11:57:00 -07:00
funlockfile.c Add pthread attributes and other libc functions 2022-09-07 05:28:32 -07:00
fwritable.c Work towards improving signals and processes 2021-01-27 19:34:02 -08:00
fwrite.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
fwrite_unlocked.c Reduce build graph by another eight percent 2022-08-13 13:11:56 -07:00
fwriting.c Work towards improving signals and processes 2021-01-27 19:34:02 -08:00
g_rando.S Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
gb18030.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
gcvt.c Add pthread attributes and other libc functions 2022-09-07 05:28:32 -07:00
getc.c Make more fixes and improvements 2022-06-13 11:02:13 -07:00
getc_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
getchar.c Apply even more fixups 2022-06-12 11:57:00 -07:00
getchar_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
getdelim.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
getdelim_unlocked.c Unbloat the build 2022-08-11 00:15:29 -07:00
getentropy.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
getline.c Fix some issues and do some code cleanup 2022-05-23 10:15:53 -07:00
getrandom.c vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
gets.c Change license 2020-12-27 17:18:44 -08:00
getwc.c Apply even more fixups 2022-06-12 11:57:00 -07:00
getwc_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
getwchar.c Apply even more fixups 2022-06-12 11:57:00 -07:00
getwchar_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
hex.internal.h Add function for creating hex string literals 2021-08-07 07:05:19 -07:00
hkscs.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
iconv.c Tidy up the threading implementation 2022-09-10 02:56:25 -07:00
iconv.h Add more missing libc functionality 2022-08-06 10:50:51 -07:00
internal.h Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
jis0208.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
joinstrlist.c Simplify redbean serialization code 2022-09-06 20:07:29 -07:00
kappendf.c Add Linux ptrace() tutorial 2022-03-24 08:00:36 -07:00
ksc.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
kvappendf.c Unbloat the build 2022-08-11 00:15:29 -07:00
lcg.internal.h Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
legacychars.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
lemur64.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
lock.internal.h Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
mkdtemp.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
mkostemp.c Change license 2020-12-27 17:18:44 -08:00
mkostemps.c Import C++ Standard Template Library 2022-03-22 06:41:54 -07:00
mkostempsm.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
mkstemp.c Change license 2020-12-27 17:18:44 -08:00
mkstemps.c Change license 2020-12-27 17:18:44 -08:00
mktemp.c Change license 2020-12-27 17:18:44 -08:00
mt19937.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
paginate.c Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
pclose.c Reduce makefile dependencies by 10% 2022-06-08 20:01:28 -07:00
popen.c vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
printf.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
putc.c Apply even more fixups 2022-06-12 11:57:00 -07:00
putc_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
putchar.c Apply even more fixups 2022-06-12 11:57:00 -07:00
putchar_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
puts.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
putwc.c Apply even more fixups 2022-06-12 11:57:00 -07:00
putwc_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
putwchar.c Apply even more fixups 2022-06-12 11:57:00 -07:00
putwchar_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
rand.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
rand.h Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
random.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
rdrand.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
rdrand_init.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
rdseed.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
readdir64.S Tidy up the threading implementation 2022-09-10 02:56:25 -07:00
real1.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
real2.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
real3.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
revjis.inc Add more missing libc functionality 2022-08-06 10:50:51 -07:00
rewind.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
rngset.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
scanf.c Change license 2020-12-27 17:18:44 -08:00
setbuf.c Make major improvements to stdio 2021-03-26 22:31:41 -07:00
setbuffer.c Make major improvements to stdio 2021-03-26 22:31:41 -07:00
setlinebuf.c Make major improvements to stdio 2021-03-26 22:31:41 -07:00
setvbuf.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
sortstrlist.c Simplify redbean serialization code 2022-09-06 20:07:29 -07:00
spawn.c Improve system calls 2022-07-08 06:42:03 -07:00
spawn.h Improve system call polyfills 2021-03-08 10:07:02 -08:00
spawna.c Improve system calls 2022-07-08 06:42:03 -07:00
spawna.internal.h Add posix_spawn (#114) 2021-03-07 20:14:07 -08:00
spawnf.c Improve LLVM compatibility a little bit 2021-05-16 20:34:46 -07:00
spawnp.c Make improvements 2022-04-28 09:57:07 -07:00
srand.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
stdbuf.c Make major improvements to stdio 2021-03-26 22:31:41 -07:00
stderr-init.S Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
stderr.c Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
stdin-init.S Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
stdin.c Remove more nonstandard stuff from cosmopolitan.h 2021-03-01 00:18:23 -08:00
stdio.h Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
stdio.mk Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
stdio_ext.h Work towards improving signals and processes 2021-01-27 19:34:02 -08:00
stdout-init.S Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
stdout.c Fold LIBC_BITS into LIBC_INTRIN 2022-08-11 12:13:18 -07:00
strfry.c Fold LIBC_ALG into LIBC_MEM 2022-08-13 08:32:34 -07:00
strlist.internal.h Simplify redbean serialization code 2022-09-06 20:07:29 -07:00
system.c vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
systemexec.c vista: backport execve escaping and using cocmd as shell for system, etc. (#660) 2022-10-11 21:17:50 -07:00
temp.h Add more missing libc functionality 2022-08-06 10:50:51 -07:00
tmpfile.c Fix some bugs 2022-08-14 13:28:07 -07:00
ungetc.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
ungetc_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
ungetwc.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
ungetwc_unlocked.c Apply even more fixups 2022-06-12 11:57:00 -07:00
vappendf.c Unbloat the build 2022-08-11 00:15:29 -07:00
vfprintf.c Remove stdio lock macros from amalgamation 2022-09-10 12:03:36 -07:00
vfprintf_unlocked.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
vfscanf.c Change license 2020-12-27 17:18:44 -08:00
vigna.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
vprintf.c Use re-entrant locks on stdio 2022-05-22 08:28:33 -07:00
vscanf.c Change license 2020-12-27 17:18:44 -08:00
xorshift.h Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
xorshift32.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00
xorshift64.c Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN 2022-08-11 12:32:00 -07:00