From nobody@FreeBSD.org  Sat Jan 30 09:50:01 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 884C51065672
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 30 Jan 2010 09:50:01 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 7811B8FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 30 Jan 2010 09:50:01 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o0U9o1kC038894
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 30 Jan 2010 09:50:01 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o0U9o1bm038891;
	Sat, 30 Jan 2010 09:50:01 GMT
	(envelope-from nobody)
Message-Id: <201001300950.o0U9o1bm038891@www.freebsd.org>
Date: Sat, 30 Jan 2010 09:50:01 GMT
From: Mikolaj Golub <to.my.trociny@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] incorrect regexp matching in awk(1)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>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:
