NetBSD Problem Report #57655

From gson@gson.org  Thu Oct 12 16:05:20 2023
Return-Path: <gson@gson.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id BAEC41A9238
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 12 Oct 2023 16:05:19 +0000 (UTC)
Message-Id: <20231012160514.2FB16253F95@guava.gson.org>
Date: Thu, 12 Oct 2023 19:05:14 +0300 (EEST)
From: gson@gson.org (Andreas Gustafsson)
Reply-To: gson@gson.org (Andreas Gustafsson)
To: gnats-bugs@NetBSD.org
Subject: zgrep(1) returns incorrect exit status
X-Send-Pr-Version: 3.95

>Number:         57655
>Category:       bin
>Synopsis:       zgrep(1) returns incorrect exit status
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 12 16:10:00 +0000 2023
>Last-Modified:  Sat Oct 14 06:35:01 +0000 2023
>Originator:     Andreas Gustafsson
>Release:        NetBSD-current, source date 2023.10.11.19.57.25
>Organization:

>Environment:
System: NetBSD
Architecture: i386
Machine: i386
>Description:

When zgrep is run with a file argument and the file does not contain
the given pattern, it incorrectly returns an exit status of 0,
contrary to what the "EXIT STATUS" section of the zgrep(1) man page
says.

>How-To-Repeat:

$ >f
$ grep a f
$ echo $?
1
$ gzip f
$ zgrep a f.gz
$ echo $?
0

>Fix:

>Audit-Trail:
From: RVP <rvp@SDF.ORG>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/57655: zgrep(1) returns incorrect exit status
Date: Fri, 13 Oct 2023 23:17:08 +0000 (UTC)

 On Thu, 12 Oct 2023, Andreas Gustafsson wrote:

 > When zgrep is run with a file argument and the file does not contain
 > the given pattern, it incorrectly returns an exit status of 0,
 > contrary to what the "EXIT STATUS" section of the zgrep(1) man page
 > says.
 >
 >> How-To-Repeat:
 >
 > $ >f
 > $ grep a f
 > $ echo $?
 > 1
 > $ gzip f
 > $ zgrep a f.gz
 > $ echo $?
 > 0
 >
 >> Fix:
 >

 Please try:

 ```
 --- zgrep.orig	2023-10-01 06:55:27.000000000 +0000
 +++ zgrep	2023-10-13 23:13:40.742454000 +0000
 @@ -111,16 +111,19 @@
   then
       # ... on stdin
       ${zcat} -fq - | ${grep} ${grep_args} -- "${pattern}" -
 +    rc=$?
   else
       # ... on all files given on the command line
       if [ ${silent} -lt 1 -a $# -gt 1 ]; then
   	grep_args="-H ${grep_args}"
       fi
 +    rc=0
       while [ $# -gt 0 ]
       do
   	${zcat} -fq -- "$1" | ${grep} --label="${1}" ${grep_args} -- "${pattern}" -
 +	[ $? -eq 0 ] || rc=$?
   	shift
       done
   fi

 -exit 0
 +exit $rc
 ```

 -RVP

From: Andreas Gustafsson <gson@gson.org>
To: RVP <rvp@SDF.ORG>
Cc: gnats-bugs@netbsd.org
Subject: Re: bin/57655: zgrep(1) returns incorrect exit status
Date: Sat, 14 Oct 2023 09:30:23 +0300

 RVP wrote:
 >  Please try:

 The patch had been mangled by gnats so I had to apply it manually,
 but other than that, it looks good to me.
 -- 
 Andreas Gustafsson, gson@gson.org

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.