From owner-svn-src-all@FreeBSD.ORG Sun Mar 7 18:31:45 2010 Return-Path: Delivered-To: svn-src-all@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E8034106567C; Sun, 7 Mar 2010 18:31:45 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (nagual.pp.ru [194.87.13.69]) by mx1.freebsd.org (Postfix) with ESMTP id 123B68FC1D; Sun, 7 Mar 2010 18:31:44 +0000 (UTC) Received: from nagual.pp.ru (ache@localhost [127.0.0.1]) by nagual.pp.ru (8.14.3/8.14.3) with ESMTP id o27IVgS8050632; Sun, 7 Mar 2010 21:31:42 +0300 (MSK) (envelope-from ache@nagual.pp.ru) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nagual.pp.ru; s=default; t=1267986702; bh=1bYN/Z3kFayxyNLqnziXZyxJWyMEHwfZhJ3sJXt68cc=; l=1704; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To; b=o9ZpNRttrWll7yZOl602UP1IrnQ/yPhvegmvCUNU0+SpAemCjA1yPRVs//lmT7DPG /pbN0+Hq3kdRZ0dnkYFfMcJZARyOB4x364KddpFkoT92iVpntNVUb9UsyHC/CNYUxP 5IOgCPnJA9rFevv9ri6YMoBn4DVukWUwV+x9DkGI= Received: (from ache@localhost) by nagual.pp.ru (8.14.3/8.14.3/Submit) id o27IVeO7050631; Sun, 7 Mar 2010 21:31:42 +0300 (MSK) (envelope-from ache) Date: Sun, 7 Mar 2010 21:31:39 +0300 From: Andrey Chernov To: Bruce Evans Message-ID: <20100307183139.GA50243@nagual.pp.ru> Mail-Followup-To: Andrey Chernov , Bruce Evans , Jaakko Heinonen , src-committers@FreeBSD.ORG, svn-src-all@FreeBSD.ORG, svn-src-head@FreeBSD.ORG References: <201003061921.o26JLv36014114@svn.freebsd.org> <20100307104626.GA9015@a91-153-117-195.elisa-laajakaista.fi> <20100308015926.O11669@delplex.bde.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100308015926.O11669@delplex.bde.org> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: svn-src-head@FreeBSD.ORG, Jaakko Heinonen , svn-src-all@FreeBSD.ORG, src-committers@FreeBSD.ORG Subject: Re: svn commit: r204803 - head/usr.bin/uniq X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Mar 2010 18:31:46 -0000 On Mon, Mar 08, 2010 at 02:17:41AM +1100, Bruce Evans wrote: > >> 3) Enforce the implied LINE_MAX limit (from POSIX definition of "text file" > >> and POSIX uniq(1) description). > > This seems to enforce a limit of LINE_MAX - 1, since space for the NUL > terminator is no longer provided. Hopfully there is no buffer overrun > from this. {LINE_MAX} _includes_ trailing \n separator according to POSIX, so real characters count is {LINE_MAX} - 1. Since we strip \n on read in uniq(1), there is a room for placing \0 appears, so no off-by-1 error. > by putting the terminating newline in the buffer. The example is also > bad in using LINE_MAX, since {LINE_MAX} is not necessarily constant. > Dynamic allocation is required to use sysconf(__SC_LINE_MAX) and once > you do that it is almost as easy to support arbitrary line lengths > like FreeBSD used to. It is right idea. I'll use sysconf(__SC_LINE_MAX) there. But currently it does the same (sysconf.c): case _SC_LINE_MAX: return (LINE_MAX); > Old versions of FreeBSD didn't have any of the dynamic allocation, or > the off-by-1 error, or the new (as I remember) error handling of > aborting for long lines; they silently discarded characters after the > LINE_MAX'th one. To add more: NetBSD uniq grows (contrary, NetBSD comm silently discarding everything afterwards). OpenBSD uniq just use fgets with 8192. GNU uniq grows. Unrestricted growing can provide problems I already mention in previous replies. Silent discarding allows some trick with input and silent wrong handling of them. What is more dangerous - very depends on situation. -- http://ache.pp.ru/