GNU bug report logs - #29613
Debian Bug#883733: grep returns 0 even if there is no match

Previous Next

Package: grep;

Reported by: "Santiago R.R." <santiagorr <at> riseup.net>

Date: Fri, 8 Dec 2017 11:12:02 UTC

Severity: normal

To reply to this bug, email your comments to 29613 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#29613; Package grep. (Fri, 08 Dec 2017 11:12:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Santiago R.R." <santiagorr <at> riseup.net>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Fri, 08 Dec 2017 11:12:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Santiago R.R." <santiagorr <at> riseup.net>
To: bug-grep <at> gnu.org
Cc: 883733 <at> bugs.debian.org
Subject: Debian Bug#883733: grep returns 0 even if there is no match
Date: Fri, 8 Dec 2017 12:11:10 +0100
Dear grep developers,

I would like to forward the report below, filed by Mathias Pietsch to
Debian. I don't want to introduce other noise than this:

$ echo 1111111111111 | grep -E '^1?$' ; echo $?
1
$ echo 1111111111111 | grep -E '^(11+)\1+$' ; echo $?
1
$ echo 1111111111111 | grep -E '^(11+)\1+$|^1?$' ; echo $?
1111111111111
0

Shouldn't the last grep command exit 1 too?

Cheers,

 -- Santiago

----- Forwarded message from Mathias Pietsch <m.pietsch <at> uke.uni-hamburg.de> -----

Date: Wed, 6 Dec 2017 23:51:52 +0100
From: Mathias Pietsch <m.pietsch <at> uke.uni-hamburg.de>
To: Debian Bug Tracking System <submit <at> bugs.debian.org>
Subject: Bug#883733: grep returns 0 even if there is no match
X-Mailer: reportbug 7.1.7

Package: grep
Version: 2.27-2
Severity: normal
Tags: upstream

when trying to test this famous regexp for matching non-prime numbers
(^1?$|^(11+?)\1+$) which works fine with 'grep -P', i wondered if it
also would work without the non-greedy quantifier so egrep or even
plain grep could use it, and found the following problem e.g., with the
prime number 13:

$ echo "1111111111111" | grep -E '^(11+)\1+$|^1?$' || echo prime
1111111111111

the expected output would have been 'prime' because '1111111111111'
doesn't match '^1?$' and is also no concatanation of two or more
'11', two or more '111', ... opposite to the orignal perl-style
non-greedy version, here the substrings should be tested for a match
beginning with the longest (13 x '1') down to the shortest ('11').

next i removed the empty line term from the regexp (i.e., the '?' from
the '^1?$' term):

$ echo "1111111111111" | grep -E '^(11+)\1+$|^1$' || echo prime
prime

now the result is correct. but since the input in not an empty line,
using '^(11+)\1+$|^1?$' or '^(11+)\1+$|^1$' should not make any
difference.

(making the empty line term a separate term '^(11+)\1+$|^1$|^$' doesn't
change anything. the same is true with using plain grep and
'^\(11\+\)\1\+$\|^1\?$' or '^\(11\+\)\1\+$\|^1$\|^$'.)

this bug also appears in the original upstream version 3.1
(http://ftp.gnu.org/gnu/grep/grep-3.1.tar.xz)


-- System Information:
Debian Release: 9.3
  APT prefers proposed-updates
  APT policy: (500, 'proposed-updates'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.9.0-4-amd64 (SMP w/4 CPU cores)
Locale: LANG=C, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8), LANGUAGE=C (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Init: sysvinit (via /sbin/init)

Versions of packages grep depends on:
ii  dpkg          1.18.24
ii  install-info  6.3.0.dfsg.1-1+b2
ii  libc6         2.24-11+deb9u2
ii  libpcre3      2:8.39-3

grep recommends no packages.

Versions of packages grep suggests:
ii  libpcre3  2:8.39-3

-- no debconf information


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts;
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

SAVE PAPER - THINK BEFORE PRINTING



----- End forwarded message -----




Information forwarded to bug-grep <at> gnu.org:
bug#29613; Package grep. (Fri, 08 Dec 2017 18:36:02 GMT) Full text and rfc822 format available.

Message #8 received at 29613 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: "Santiago R.R." <santiagorr <at> riseup.net>, 29613 <at> debbugs.gnu.org
Cc: 883733 <at> bugs.debian.org
Subject: Re: bug#29613: Debian Bug#883733: grep returns 0 even if there is no
 match
Date: Fri, 8 Dec 2017 10:34:53 -0800
On 12/08/2017 03:11 AM, Santiago R.R. wrote:
> $ echo 1111111111111 | grep -E '^(11+)\1+$|^1?$' ; echo $?
> 1111111111111
> 0
>
> Shouldn't the last grep command exit 1 too?

Yes it should. This appears to be due to a longstanding bug in the glibc 
regular expression matcher. See:

https://sourceware.org/bugzilla/show_bug.cgi?id=11053





Information forwarded to bug-grep <at> gnu.org:
bug#29613; Package grep. (Fri, 08 Dec 2017 18:40:02 GMT) Full text and rfc822 format available.

Message #11 received at 29613 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: "Santiago R.R." <santiagorr <at> riseup.net>
Cc: 883733 <at> bugs.debian.org, 29613 <at> debbugs.gnu.org
Subject: Re: bug#29613: Debian Bug#883733: grep returns 0 even if there is no
 match
Date: Fri, 8 Dec 2017 10:38:45 -0800
On Fri, Dec 8, 2017 at 3:11 AM, Santiago R.R. <santiagorr <at> riseup.net> wrote:
> Dear grep developers,
>
> I would like to forward the report below, filed by Mathias Pietsch to
> Debian. I don't want to introduce other noise than this:
>
> $ echo 1111111111111 | grep -E '^1?$' ; echo $?
> 1
> $ echo 1111111111111 | grep -E '^(11+)\1+$' ; echo $?
> 1
> $ echo 1111111111111 | grep -E '^(11+)\1+$|^1?$' ; echo $?
> 1111111111111
> 0
>
> Shouldn't the last grep command exit 1 too?
>
> Cheers,
>
>  -- Santiago
>
> ----- Forwarded message from Mathias Pietsch <m.pietsch <at> uke.uni-hamburg.de> -----
>
> Date: Wed, 6 Dec 2017 23:51:52 +0100
> From: Mathias Pietsch <m.pietsch <at> uke.uni-hamburg.de>
> To: Debian Bug Tracking System <submit <at> bugs.debian.org>
> Subject: Bug#883733: grep returns 0 even if there is no match
> X-Mailer: reportbug 7.1.7
>
> Package: grep
> Version: 2.27-2
> Severity: normal
> Tags: upstream
>
> when trying to test this famous regexp for matching non-prime numbers
> (^1?$|^(11+?)\1+$) which works fine with 'grep -P', i wondered if it
> also would work without the non-greedy quantifier so egrep or even
> plain grep could use it, and found the following problem e.g., with the
> prime number 13:
>
> $ echo "1111111111111" | grep -E '^(11+)\1+$|^1?$' || echo prime
> 1111111111111
>
> the expected output would have been 'prime' because '1111111111111'
> doesn't match '^1?$' and is also no concatanation of two or more
> '11', two or more '111', ... opposite to the orignal perl-style
> non-greedy version, here the substrings should be tested for a match
> beginning with the longest (13 x '1') down to the shortest ('11').
>
> next i removed the empty line term from the regexp (i.e., the '?' from
> the '^1?$' term):
>
> $ echo "1111111111111" | grep -E '^(11+)\1+$|^1$' || echo prime
> prime
>
> now the result is correct. but since the input in not an empty line,
> using '^(11+)\1+$|^1?$' or '^(11+)\1+$|^1$' should not make any
> difference.
>
> (making the empty line term a separate term '^(11+)\1+$|^1$|^$' doesn't
> change anything. the same is true with using plain grep and
> '^\(11\+\)\1\+$\|^1\?$' or '^\(11\+\)\1\+$\|^1$\|^$'.)
>
> this bug also appears in the original upstream version 3.1
> (http://ftp.gnu.org/gnu/grep/grep-3.1.tar.xz)

Yikes! Thanks for forwarding that.
That is indeed a bug. I think it must be due to a bug in glibc's
regexp code, since that's the matcher that grep uses when there is any
back-reference.




This bug report was last modified 6 years and 111 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.