Date: Thu, 23 Sep 2021 13:06:12 -0700 From: Bryan Drewery <bdrewery@FreeBSD.org> To: Kyle Evans <kevans@FreeBSD.org>, src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: f555b39e6bb7 - main - man: reset OPTIND before parsing args Message-ID: <33438d0b-1925-8d44-83bb-62054b141635@FreeBSD.org> In-Reply-To: <202109231914.18NJELZU023086@gitrepo.freebsd.org> References: <202109231914.18NJELZU023086@gitrepo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --XInPtLUnSy9zfyorvKeTTNAg8D5LojOC5 Content-Type: multipart/mixed; boundary="mCNiFLnztWUqqQQdqoZG1wz328xTcPbXV"; protected-headers="v1" From: Bryan Drewery <bdrewery@FreeBSD.org> To: Kyle Evans <kevans@FreeBSD.org>, src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Message-ID: <33438d0b-1925-8d44-83bb-62054b141635@FreeBSD.org> Subject: Re: git: f555b39e6bb7 - main - man: reset OPTIND before parsing args References: <202109231914.18NJELZU023086@gitrepo.freebsd.org> In-Reply-To: <202109231914.18NJELZU023086@gitrepo.freebsd.org> --mCNiFLnztWUqqQQdqoZG1wz328xTcPbXV Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 9/23/2021 12:14 PM, Kyle Evans wrote: > The branch main has been updated by kevans: >=20 > URL: https://cgit.FreeBSD.org/src/commit/?id=3Df555b39e6bb7cbfbe1905e90= f64c4dfc4456fabb >=20 > commit f555b39e6bb7cbfbe1905e90f64c4dfc4456fabb > Author: Kyle Evans <kevans@FreeBSD.org> > AuthorDate: 2021-09-22 19:58:19 +0000 > Commit: Kyle Evans <kevans@FreeBSD.org> > CommitDate: 2021-09-23 19:13:34 +0000 >=20 > man: reset OPTIND before parsing args > =20 > From jilles: POSIX requires that a script set `OPTIND=3D1` before u= sing > different sets of parameters with `getopts`, or the results will be= > unspecified. > =20 > 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 th= e > 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. > =20 > 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(+) >=20 > 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 > =20 > + OPTIND=3D1 > while getopts 'Ldq' cmd_arg; do > case "${cmd_arg}" in > L) Lflag=3DLflag ;; 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. --=20 Bryan Drewery --mCNiFLnztWUqqQQdqoZG1wz328xTcPbXV-- --XInPtLUnSy9zfyorvKeTTNAg8D5LojOC5 Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wsB5BAABCAAjFiEE+Rc8ssOq6npcih8JNddxu25Gl88FAmFM3jQFAwAAAAAACgkQNddxu25Gl8// fAf+O3YXbK0GFvjhmxxzbVODUS2kQAq/UlrYfcNxWsxd0xGlqSbdu+N2Ky5bsnDqVJ4f8kUlnDwa OSlDhox/c4STZBBnTHZPTrS6wHnon2QQbQpdFyEKgInRtSf3TfvChbHU2kkQIiPcr5uWEgSg4TwV GnzvAKhccr/iEy8Vo7x/mIuqoJKyVwNamSNzQcy15hwDue4/PkG4Bu5QKRtMJidBJ3w0Wi84GQ6I GAGb8leIiCSvuanNucPXMso5OwaJcCU+Qb/uIIwTok4x2Bm+mibmzu+bOGap6Jl1Uase/F19+tho hY4YVViWEQyMgB3NPe9vTi8cV0nTtMjS8z108Jyr3g== =X6MU -----END PGP SIGNATURE----- --XInPtLUnSy9zfyorvKeTTNAg8D5LojOC5--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?33438d0b-1925-8d44-83bb-62054b141635>