]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
sh: Make getopts memory-safe if with changing arguments.
authorjilles <jilles@FreeBSD.org>
Sun, 26 Oct 2014 17:50:33 +0000 (17:50 +0000)
committerjilles <jilles@FreeBSD.org>
Sun, 26 Oct 2014 17:50:33 +0000 (17:50 +0000)
commitbc5702addf6a68dc471c6dd3884ca164587b8271
tree8484fb30e43bfd82dc96d44ef76a402bd991793c
parent0963d8042b3129788a04f3b99596ffeef457dc3f
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.
bin/sh/eval.c
bin/sh/options.c
bin/sh/options.h
bin/sh/tests/builtins/getopts9.0 [new file with mode: 0644]
bin/sh/tests/builtins/getopts9.0.stdout [new file with mode: 0644]