diff options
author | jilles <jilles@FreeBSD.org> | 2014-10-26 17:50:33 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2014-10-26 17:50:33 +0000 |
commit | bc5702addf6a68dc471c6dd3884ca164587b8271 (patch) | |
tree | 8484fb30e43bfd82dc96d44ef76a402bd991793c /bin/sh/eval.c | |
parent | 0963d8042b3129788a04f3b99596ffeef457dc3f (diff) | |
download | FreeBSD-src-bc5702addf6a68dc471c6dd3884ca164587b8271.zip FreeBSD-src-bc5702addf6a68dc471c6dd3884ca164587b8271.tar.gz |
sh: Make getopts memory-safe if with changing arguments.
POSIX does not permit to continuing a getopts loop with different
arguments. For parsing the positional parameters, we handle this case by
resetting the getopts state when the positional parameters are changed in
any way (and the getopts state is local to a function). However, in the
syntax getopts <optstring> <var> <arg...>, changes could lead to invalid
memory access.
In the syntax getopts <optstring> <var> <arg...>, store a copy of the
arguments and continue to use them until getopts is reset.
Diffstat (limited to 'bin/sh/eval.c')
-rw-r--r-- | bin/sh/eval.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 38e227c..c1a9cdb 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -1039,6 +1039,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) shellparam.reset = 1; shellparam.nparam = argc - 1; shellparam.p = argv + 1; + shellparam.optp = NULL; shellparam.optnext = NULL; INTOFF; savelocalvars = localvars; |