GNU bug report logs - #36148
inconsistent behaviour with anchored regex containing back-references

Previous Next

Package: grep;

Reported by: g1pi <at> libero.it

Date: Sun, 9 Jun 2019 15:30:02 UTC

Severity: normal

Merged with 26864

Full log


View this message in rfc822 format

From: Thorsten Glaser <tg <at> mirbsd.de>
To: 36148 <at> debbugs.gnu.org
Subject: bug#36148: Debian Bug#930247: grep: does not handle backreferences correctly, violating POSIX
Date: Fri, 2 Dec 2022 01:21:01 +0000 (UTC)
Please fix this bug, it’s really bad and embarrassing.

It looks like instead of matching “the same[…]string of characters as
was matched by a subexpression[…]preceding”, it matches with the same
as the previous subexpression used?

---------- Forwarded message ----------
Message-ID: <166994354000.10956.15575266799036445295.reportbug <at> x61w.mirbsd.org>
Date: Fri, 02 Dec 2022 02:12:20 +0100
Subject: Bug#930247: grep: inconsistent behaviour with anchored regex containing
     back-references

Package: grep
Version: 3.6-1
Followup-For: Bug #930247
X-Debbugs-Cc: tg <at> mirbsd.de
Control: found 930247 3.8-3
Control: severity 930247 serious
Control: retitle 930247 grep: does not handle backreferences correctly, violating POSIX

I’m running into this, in stable and unstable both:

(sid-amd64)tglase <at> tglase:/tmp $ cat x
Total failed: 0
Total failed: 1 (1 ignored)
Total failed: 2 (1 ignored)
Total failed: 1 (2 ignored)
Total failed: 1
Total failed: 111
(sid-amd64)tglase <at> tglase:/tmp $ grep -e '^Total failed: 0$' -e '^Total failed: \([0-9]*\) (\1 ignored)$' x
Total failed: 0
Total failed: 1 (1 ignored)
Total failed: 2 (1 ignored)
Total failed: 1 (2 ignored)

By contrast, BSD handles it correctly:

tg <at> tglase-bsd:/tmp $ grep -e '^Total failed: 0$' -e '^Total failed: \([0-9]*\) (\1 ignored)$' x
Total failed: 0
Total failed: 1 (1 ignored)

POSIX:

    3. The back-reference expression '\n' shall match the same (possibly
       empty) string of characters as was matched by a subexpression
       enclosed between "\(" and "\)" preceding the '\n'. The character

via https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03
from https://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html

Please fix this clear standards violation; it makes grep
virtually unusable.



-- System Information:
Debian Release: 11.5
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 5.10.0-19-amd64 (SMP w/2 CPU threads)
Locale: LANG=C, LC_CTYPE=C (charmap=UTF-8) (ignored: LC_ALL set to C.UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /bin/lksh
Init: sysvinit (via /sbin/init)

Versions of packages grep depends on:
ii  dpkg          1.20.12
ii  install-info  6.7.0.dfsg.2-6
ii  libc6         2.31-13+deb11u5
ii  libpcre3      2:8.39-13

grep recommends no packages.

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

-- no debconf information




This bug report was last modified 84 days ago.

Previous Next


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