HardenedBSD/lib
Jilles Tjoelker d358fa780b wordexp: Rewrite to make WRDE_NOCMD reliable.
Shell syntax is too complicated to detect command substitution and unquoted
operators reliably without implementing much of sh's parser. Therefore, have
sh do this detection.

While changing sh's support anyway, also read input from a pipe instead of
arguments to avoid {ARG_MAX} limits and improve privacy, and output count
and length using 16 instead of 8 digits.

The basic concept is:
execl("/bin/sh", "sh", "-c", "freebsd_wordexp ${1:+\"$1\"} -f "$2",
    "", flags & WRDE_NOCMD ? "-p" : "", <pipe with words>);

The WRDE_BADCHAR error is still implemented in libc. POSIX requires us to
fail strings containing unquoted braces with code WRDE_BADCHAR. Since this
is normally not a syntax error in sh, there is still a need for checking
code in libc, we_check().

The new we_check() is an optimistic check that all the characters
  <newline> | & ; < > ( ) { }
are quoted. To avoid duplicating too much sh logic, such characters are
permitted when quoting characters are seen, even if the quoting characters
may themselves be quoted. This code reports all WRDE_BADCHAR errors; bad
characters that get past it and are a syntax error in sh return WRDE_SYNTAX.

Although many implementations of WRDE_NOCMD erroneously allow some command
substitutions (and ours even documented this), there appears to be code that
relies on its security (codesearch.debian.net shows quite a few uses).
Passing untrusted data to wordexp() still exposes a denial of service
possibility and a fairly large attack surface.

Reviewed by:	wblock (man page only)
MFC after:	2 weeks
Relnotes:	yes
Security:	fixes command execution with wordexp(untrusted, WRDE_NOCMD)
2015-09-30 21:32:29 +00:00
..
atf
clang META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
csu Annotate arm userspace assembler sources stating their tolerance to 2015-09-29 16:09:58 +00:00
libalias
libarchive
libauditd
libbegemot
libblocksruntime META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libbluetooth
libbsdstat
libbsm
libbsnmp
libbz2
libc wordexp: Rewrite to make WRDE_NOCMD reliable. 2015-09-30 21:32:29 +00:00
libc_nonshared
libc++
libcalendar
libcam
libcapsicum
libcasper
libclang_rt
libcom_err
libcompat
libcompiler_rt Annotate arm userspace assembler sources stating their tolerance to 2015-09-29 16:09:58 +00:00
libcrypt META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libcuse META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libcxxrt META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libdevctl
libdevinfo
libdevstat
libdpv
libdwarf
libedit
libefi
libelf
libelftc
libevent META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libexecinfo
libexpat
libfetch Fix non-POSIX-compliant use of getaddrinfo in libfetch 2015-09-25 14:24:23 +00:00
libfigpar
libgeom
libgpib META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libgpio
libgssapi
libiconv_modules META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libipsec
libjail
libkiconv
libkvm
libldns
liblzma Replace beforeinstall: handling with FILES. 2015-09-18 23:49:32 +00:00
libmagic MFV r288140: update file to 5.25. 2015-09-23 05:39:20 +00:00
libmd
libmemstat
libmilter META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libmp
libmt
libnandfs
libnetbsd
libnetgraph
libngatm
libnv
libohash
libopie
libpam Restore the upstream (and documented) behavior of searching for modules 2015-09-21 17:26:35 +00:00
libpcap
libpjdlog
libpmc
libproc Enable libproc symbol_lookup tests on arm64 2015-08-31 20:30:06 +00:00
libprocstat Detect badly behaved coredump note helpers 2015-09-03 20:32:10 +00:00
libradius
librpcsec_gss META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
librpcsvc
librt
librtld_db
libsbuf
libsdp
libsm Update META_MODE dependencies. 2015-09-17 05:06:34 +00:00
libsmb META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libsmdb
libsmutil
libsqlite3
libstand META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libstdbuf META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libstdthreads META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libtacplus
libtelnet
libthr Style. Use ANSI definition, wrap long lines, no initialization in 2015-09-08 08:48:53 +00:00
libthread_db
libucl
libufs
libugidfw Fix 'ugidfw remove' after r284251 incorrectly changed it. 2015-09-29 18:48:12 +00:00
libulog
libunbound META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libusb Replace beforeinstall: handling with FILES. 2015-09-18 23:49:32 +00:00
libusbhid
libutil Detect badly behaved coredump note helpers 2015-09-03 20:32:10 +00:00
libvgl META_MODE: Remove DEP_RELDIR from Makefile.depend files. 2015-09-25 19:26:08 +00:00
libvmmapi
libwrap
libxo Update META_MODE dependencies. 2015-09-17 05:06:34 +00:00
liby
libypclnt
libz Replace beforeinstall: handling with FILES. 2015-09-18 23:49:32 +00:00
msun
ncurses Add missing CLEANFILES. 2015-09-26 01:04:52 +00:00
tests
Makefile
Makefile.inc