summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-10-24 20:45:13 +0000
committerjilles <jilles@FreeBSD.org>2010-10-24 20:45:13 +0000
commite5f0dbf76ca1039abc78f0a61e6562f88e73326b (patch)
treee267217dcd6626c2c419ec08a528e096dde4f3cf /bin
parentc487e17b8fb428abe374fa4820d1b3628c383af5 (diff)
downloadFreeBSD-src-e5f0dbf76ca1039abc78f0a61e6562f88e73326b.zip
FreeBSD-src-e5f0dbf76ca1039abc78f0a61e6562f88e73326b.tar.gz
sh: Make sure defined functions can actually be called.
Add some conservative checks on function names: - Disallow expansions or quoting characters; these can only be called via strange control characters - Disallow '/'; these functions cannot be called anyway, as exec.c assumes they are pathnames - Make the CTL* bytes work properly in function names. These are syntax errors. POSIX does not require us to support more than names (letters, digits and underscores, not starting with a digit), but I do not want to restrict it that much at this time. Exp-run done by: pav (with some other sh(1) changes)
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/parser.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index 6c504e5..ec1510b 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -639,10 +639,14 @@ simplecmd(union node **rpp, union node *redir)
if (readtoken() != TRP)
synexpect(TRP);
funclinno = plinno;
-#ifdef notdef
- if (! goodname(n->narg.text))
+ /*
+ * - Require plain text.
+ * - Functions with '/' cannot be called.
+ */
+ if (!noexpand(n->narg.text) || quoteflag ||
+ strchr(n->narg.text, '/'))
synerror("Bad function name");
-#endif
+ rmescapes(n->narg.text);
n->type = NDEFUN;
n->narg.next = command();
funclinno = 0;
OpenPOWER on IntegriCloud