]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
man: reset OPTIND before parsing args
authorKyle Evans <kevans@FreeBSD.org>
Wed, 22 Sep 2021 19:58:19 +0000 (14:58 -0500)
committerKyle Evans <kevans@FreeBSD.org>
Thu, 23 Sep 2021 19:13:34 +0000 (14:13 -0500)
commitf555b39e6bb7cbfbe1905e90f64c4dfc4456fabb
tree0819de8e13a79ad9cfad6831c9be4ae8c39dc8ac
parentef50d5fbc39fc39970eab1234222b5ac1d9ba74c
man: reset OPTIND before parsing args

From jilles: POSIX requires that a script set `OPTIND=1` before using
different sets of parameters with `getopts`, or the results will be
unspecified.

The specific problem observed here is that we would execute `man -f` or
`man -k` without cleaning up state from man_parse_args()' `getopts`
loop.  FreeBSD's /bin/sh seems to reset OPTIND to 1 after we hit the
second getopts loop, rendering the following shift harmless; other
/bin/sh implementations will leave it at what we came into the loop at
(e.g., bash as /bin/sh), shifting off any keywords that we had.

Input from: jilles
Reviewed by: allanjude, bapt, imp
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D32063
usr.bin/man/man.sh