summaryrefslogtreecommitdiffstats
path: root/bin/sh/builtins.def
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2015-09-30 21:32:29 +0000
committerjilles <jilles@FreeBSD.org>2015-09-30 21:32:29 +0000
commitaca221db9d8ee973f5ca86a03adfddf468891409 (patch)
treec0c8b623265338ef1866c1e7413af3622fae0154 /bin/sh/builtins.def
parentbaa76ea3b344be8defab8d337442ca3b301a126c (diff)
downloadFreeBSD-src-aca221db9d8ee973f5ca86a03adfddf468891409.zip
FreeBSD-src-aca221db9d8ee973f5ca86a03adfddf468891409.tar.gz
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)
Diffstat (limited to 'bin/sh/builtins.def')
-rw-r--r--bin/sh/builtins.def1
1 files changed, 1 insertions, 0 deletions
diff --git a/bin/sh/builtins.def b/bin/sh/builtins.def
index 1cbeea9..8807347 100644
--- a/bin/sh/builtins.def
+++ b/bin/sh/builtins.def
@@ -65,6 +65,7 @@ exportcmd -s export -s readonly
#exprcmd expr
falsecmd false
fgcmd -j fg
+freebsd_wordexpcmd freebsd_wordexp
getoptscmd getopts
hashcmd hash
histcmd -h fc
OpenPOWER on IntegriCloud