From owner-freebsd-bugs@FreeBSD.ORG Sat Nov 28 17:00:04 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E62F61065676 for ; Sat, 28 Nov 2009 17:00:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id BD3828FC27 for ; Sat, 28 Nov 2009 17:00:03 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id nASH03bB076025 for ; Sat, 28 Nov 2009 17:00:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id nASH03P7076024; Sat, 28 Nov 2009 17:00:03 GMT (envelope-from gnats) Resent-Date: Sat, 28 Nov 2009 17:00:03 GMT Resent-Message-Id: <200911281700.nASH03P7076024@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "D'Arcy Cain" Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 16E25106566B for ; Sat, 28 Nov 2009 16:59:55 +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 05E9F8FC1D for ; Sat, 28 Nov 2009 16:59:55 +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 nASGxsmH077805 for ; Sat, 28 Nov 2009 16:59:54 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id nASGxsoS077804; Sat, 28 Nov 2009 16:59:54 GMT (envelope-from nobody) Message-Id: <200911281659.nASGxsoS077804@www.freebsd.org> Date: Sat, 28 Nov 2009 16:59:54 GMT From: "D'Arcy Cain" To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/140976: comm(1) mishandles lines with tabs X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Nov 2009 17:00:04 -0000 >Number: 140976 >Category: bin >Synopsis: comm(1) mishandles lines with tabs >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Nov 28 17:00:03 UTC 2009 >Closed-Date: >Last-Modified: >Originator: D'Arcy Cain >Release: 7.2-RELEASE >Organization: NetBSD developer >Environment: FreeBSD shell.vex.net 7.2-RELEASE FreeBSD 7.2-RELEASE #0: Fri May 1 08:49:13 UTC 2009 root@walker.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 >Description: If an input file contains tabs it may not be handled correctly. In fact, the problem would happen with any character that compares lower than newline. >How-To-Repeat: Run this script. The two tests should print the same thing. #! /bin/sh TEST=/tmp/$$.test trap "rm -f $TEST.*" 0 cat << MOUSE > $TEST.1a a b c d e f e f g h i MOUSE cat << MOUSE > $TEST.1b a b e f g MOUSE tr ' ' '\t' < $TEST.1a > $TEST.2a tr ' ' '\t' < $TEST.1b > $TEST.2b echo "Test 1 (spaces) output:" comm -12 $TEST.1a $TEST.1b echo "" echo "Test 2 (tabs) output:" comm -12 $TEST.2a $TEST.2b >Fix: http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/comm/comm.c.diff?r1=1.17&r2=1.18&only_with_tag=MAIN&f=h is how I fixed it on NetBSD but you have a much different version of comm.c. The basic fix is to not read the newline. The newline is the separator between lines, not part of the line and including it causes it to be erroneously included in the comparisons. sort(1) gets this right and that's where the problem occurs. comm(1) does not agree with the sorting criteria. In NetBSD current there is a library function called getline which more or less does what the getline included in comm.c does except that it doesn't return the newline. Perhaps you should pull that in and use it instead. Don't forget to change your printf statements to add the newline. >Release-Note: >Audit-Trail: >Unformatted: