Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Jan 2010 09:50:01 GMT
From:      Mikolaj Golub <to.my.trociny@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/143365: [patch] incorrect regexp matching in awk(1)
Message-ID:  <201001300950.o0U9o1bm038891@www.freebsd.org>
Resent-Message-ID: <201001301000.o0UA08f5004905@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         143365
>Category:       bin
>Synopsis:       [patch] incorrect regexp matching in awk(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan 30 10:00:07 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Mikolaj Golub
>Release:        8.0-STABLE, 7.2-STABLE
>Organization:
>Environment:
FreeBSD zhuzha.ua1 8.0-STABLE FreeBSD 8.0-STABLE #6: Sun Jan 24 21:36:17 EET 2010     root@zhuzha.ua1:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
This problem with awk(1) regexp working incorrectly was reported to NetBSD by Aleksey Cheusov and it was fixed there.

http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=38737

FreeBSD version still has this bug:

kopusha:~% printf '\t\n' | LC_CTYPE=C awk '/^[[:cntrl:]]/ {print "It is ok"}'
It is ok
kopusha:~% printf '\t\n' | LC_CTYPE=C awk '/^[[:cntrl:]]$/ {print "It is ok"}'
kopusha:~% 

>How-To-Repeat:
printf '\t\n' | LC_CTYPE=C awk '/^[[:cntrl:]]$/ {print "It is ok"}'
>Fix:
See the attached patch adopted from NetBSD (don't build the character class table
 starting at 0, because will always be treated as the empty string).

Patch attached with submission follows:

diff -ru contrib/one-true-awk.orig/b.c contrib/one-true-awk/b.c
--- contrib/one-true-awk.orig/b.c	2007-06-05 18:33:51.000000000 +0300
+++ contrib/one-true-awk/b.c	2010-01-30 11:37:15.000000000 +0200
@@ -818,7 +818,7 @@
 				if (cc->cc_name != NULL && prestr[1 + cc->cc_namelen] == ':' &&
 				    prestr[2 + cc->cc_namelen] == ']') {
 					prestr += cc->cc_namelen + 3;
-					for (i = 0; i < NCHARS; i++) {
+					for (i = 1; i < NCHARS; i++) {
 						if (!adjbuf((char **) &buf, &bufsz, bp-buf+1, 100, (char **) &bp, "relex2"))
 						    FATAL("out of space for reg expr %.10s...", lastre);
 						if (cc->cc_func(i)) {


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001300950.o0U9o1bm038891>