git: f555b39e6bb7 - main - man: reset OPTIND before parsing args
Bryan Drewery
bdrewery at FreeBSD.org
Thu Sep 23 20:06:17 UTC 2021
On 9/23/2021 12:14 PM, Kyle Evans wrote:
> The branch main has been updated by kevans:
>
> URL: https://cgit.FreeBSD.org/src/commit/?id=f555b39e6bb7cbfbe1905e90f64c4dfc4456fabb
>
> commit f555b39e6bb7cbfbe1905e90f64c4dfc4456fabb
> Author: Kyle Evans <kevans at FreeBSD.org>
> AuthorDate: 2021-09-22 19:58:19 +0000
> Commit: Kyle Evans <kevans at FreeBSD.org>
> CommitDate: 2021-09-23 19:13:34 +0000
>
> 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 | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/usr.bin/man/man.sh b/usr.bin/man/man.sh
> index f31c464fcc8f..084f4a06829b 100755
> --- a/usr.bin/man/man.sh
> +++ b/usr.bin/man/man.sh
> @@ -243,6 +243,7 @@ is_newer() {
> manpath_parse_args() {
> local cmd_arg
>
> + OPTIND=1
> while getopts 'Ldq' cmd_arg; do
> case "${cmd_arg}" in
> L) Lflag=Lflag ;;
Not that it matters much but since this script makes use of 'local',
OPTIND and OPTARG might as well be in the list as well.
--
Bryan Drewery
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/dev-commits-src-main/attachments/20210923/d6a6a9f4/attachment.sig>
More information about the dev-commits-src-main
mailing list