From owner-dev-commits-src-branches@freebsd.org  Sun Oct  3 05:15:43 2021
Return-Path: <owner-dev-commits-src-branches@freebsd.org>
Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
 by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1B9096B0E8B;
 Sun,  3 Oct 2021 05:15:43 +0000 (UTC) (envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org
 [IPv6:2610:1c1:1:606c::19:3])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
 client-signature RSA-PSS (4096 bits) client-digest SHA256)
 (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id 4HMX9q061Cz4RT3;
 Sun,  3 Oct 2021 05:15:43 +0000 (UTC) (envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org
 [IPv6:2610:1c1:1:6068::e6a:5])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
 (Client did not present a certificate)
 by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D3AC720629;
 Sun,  3 Oct 2021 05:15:42 +0000 (UTC) (envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
 by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1935Fgu8008782;
 Sun, 3 Oct 2021 05:15:42 GMT (envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
 by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1935Fg0g008781;
 Sun, 3 Oct 2021 05:15:42 GMT (envelope-from git)
Date: Sun, 3 Oct 2021 05:15:42 GMT
Message-Id: <202110030515.1935Fg0g008781@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
 dev-commits-src-branches@FreeBSD.org
From: Kyle Evans <kevans@FreeBSD.org>
Subject: git: 0760a2e9a4d9 - stable/13 - man: reset OPTIND before parsing args
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: kevans
X-Git-Repository: src
X-Git-Refname: refs/heads/stable/13
X-Git-Reftype: branch
X-Git-Commit: 0760a2e9a4d98047042349aa1bfed9d1d0f2212e
Auto-Submitted: auto-generated
X-BeenThere: dev-commits-src-branches@freebsd.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: Commits to the stable branches of the FreeBSD src repository
 <dev-commits-src-branches.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/dev-commits-src-branches>, 
 <mailto:dev-commits-src-branches-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/dev-commits-src-branches/>
List-Post: <mailto:dev-commits-src-branches@freebsd.org>
List-Help: <mailto:dev-commits-src-branches-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/dev-commits-src-branches>, 
 <mailto:dev-commits-src-branches-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sun, 03 Oct 2021 05:15:43 -0000

The branch stable/13 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=0760a2e9a4d98047042349aa1bfed9d1d0f2212e

commit 0760a2e9a4d98047042349aa1bfed9d1d0f2212e
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2021-09-22 19:58:19 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2021-10-03 05:14:43 +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.
    
    (cherry picked from commit f555b39e6bb7cbfbe1905e90f64c4dfc4456fabb)
---
 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 ;;
@@ -426,6 +427,7 @@ man_display_page_groff() {
 
 	if [ -n "$MANROFFSEQ" ]; then
 		set -- -$MANROFFSEQ
+		OPTIND=1
 		while getopts 'egprtv' preproc_arg; do
 			case "${preproc_arg}" in
 			e)	pipeline="$pipeline | $EQN" ;;
@@ -545,6 +547,7 @@ man_find_and_display() {
 man_parse_args() {
 	local IFS cmd_arg
 
+	OPTIND=1
 	while getopts 'M:P:S:adfhkm:op:tw' cmd_arg; do
 		case "${cmd_arg}" in
 		M)	MANPATH=$OPTARG ;;
@@ -933,6 +936,7 @@ trim() {
 # Parse commandline args for whatis and apropos.
 whatis_parse_args() {
 	local cmd_arg
+	OPTIND=1
 	while getopts 'd' cmd_arg; do
 		case "${cmd_arg}" in
 		d)	debug=$(( $debug + 1 )) ;;