Bug 195792

Summary: awk mishandles [[:cntrl:]]
Product: Base System Reporter: eggert
Component: binAssignee: Andrey A. Chernov <ache>
Status: Closed FIXED    
Severity: Affects Some People CC: ache, kd-dev
Priority: --- Keywords: patch
Version: 9.1-RELEASEFlags: ache: mfc-stable11+
ache: mfc-stable10+
ache: mfc-stable9+
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Skip NUL to avoid preemptive truncation none

Description eggert 2014-12-08 01:09:36 UTC
Here's a shell session illustrating the problem:

$ export LC_ALL=C
$ export PATH=/usr/bin:/bin
$ echo x | awk '/[[:cntrl:]]/'
x

The output should be empty, but awk mistakenly acts as if "x" is a control character.

This bug broke a script that we use in GNU Emacs development; please see:

http://lists.gnu.org/archive/html/emacs-devel/2014-12/msg00704.html
Comment 1 kd-dev 2016-09-02 22:53:05 UTC
Created attachment 174328 [details]
Skip NUL to avoid preemptive truncation

The NUL character in cntrl is truncates the pattern, and an empty
pattern matches anything.  The attached patch skips NUL as a quick fix.
Comment 2 commit-hook freebsd_committer freebsd_triage 2016-09-03 23:05:40 UTC
A commit references this bug:

Author: ache
Date: Sat Sep  3 23:04:56 UTC 2016
New revision: 305365
URL: https://svnweb.freebsd.org/changeset/base/305365

Log:
  The bug:
  $ echo x | awk '/[[:cntrl:]]/'
  x

  The NUL character in cntrl class truncates the pattern, and an empty
  pattern matches anything. The patch skips NUL as a quick fix.

  PR:     195792
  Submitted by:   kdrakehp@zoho.com
  Approved by:    bwk@cs.princeton.edu (the author)
  MFC after:      3 days

Changes:
  head/contrib/one-true-awk/b.c
Comment 3 commit-hook freebsd_committer freebsd_triage 2016-09-06 00:33:16 UTC
A commit references this bug:

Author: ache
Date: Tue Sep  6 00:32:34 UTC 2016
New revision: 305447
URL: https://svnweb.freebsd.org/changeset/base/305447

Log:
  MFC r305365

  The bug:
  $ echo x | awk '/[[:cntrl:]]/'
  x

  The NUL character in cntrl class truncates the pattern, and an empty
  pattern matches anything. The patch skips NUL as a quick fix.

  PR:     195792
  Submitted by:   kdrakehp@zoho.com
  Approved by:    bwk@cs.princeton.edu (the author)

Changes:
_U  stable/10/
  stable/10/contrib/one-true-awk/b.c
Comment 4 commit-hook freebsd_committer freebsd_triage 2016-09-06 00:34:17 UTC
A commit references this bug:

Author: ache
Date: Tue Sep  6 00:33:54 UTC 2016
New revision: 305448
URL: https://svnweb.freebsd.org/changeset/base/305448

Log:
  MFC r305365

  The bug:
  $ echo x | awk '/[[:cntrl:]]/'
  x

  The NUL character in cntrl class truncates the pattern, and an empty
  pattern matches anything. The patch skips NUL as a quick fix.

  PR:     195792
  Submitted by:   kdrakehp@zoho.com
  Approved by:    bwk@cs.princeton.edu (the author)

Changes:
_U  stable/11/
  stable/11/contrib/one-true-awk/b.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2016-09-06 00:54:20 UTC
A commit references this bug:

Author: ache
Date: Tue Sep  6 00:53:21 UTC 2016
New revision: 305450
URL: https://svnweb.freebsd.org/changeset/base/305450

Log:
  MFC r305365

  The bug:
  $ echo x | awk '/[[:cntrl:]]/'
  x

  The NUL character in cntrl class truncates the pattern, and an empty
  pattern matches anything. The patch skips NUL as a quick fix.

  PR:     195792
  Submitted by:   kdrakehp@zoho.com
  Approved by:    bwk@cs.princeton.edu (the author)

Changes:
_U  stable/9/
_U  stable/9/contrib/
_U  stable/9/contrib/one-true-awk/
  stable/9/contrib/one-true-awk/b.c