From owner-freebsd-hackers@FreeBSD.ORG Wed Aug 27 01:48:46 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5A9BD1065677; Wed, 27 Aug 2008 01:48:46 +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 A7B9C8FC1C; Wed, 27 Aug 2008 01:48:45 +0000 (UTC) (envelope-from ache@nagual.pp.ru) Received: from nagual.pp.ru (ache@localhost [127.0.0.1]) by nagual.pp.ru (8.14.2/8.14.2) with ESMTP id m7R1WN9d083933; Wed, 27 Aug 2008 05:32:23 +0400 (MSD) (envelope-from ache@nagual.pp.ru) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nagual.pp.ru; s=default; t=1219800743; bh=rofMg4Dp3slkqBp0rG72cR3xhRwXhy4nubi8W3P Shzg=; l=1398; h=Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:In-Reply-To; b=HmLSiwDzIwbMrGzySKS5RvMlg yXO2vG7chgbVk3a1hEIwvGqRWPcHNmPr8wMXisOt7Lez8KQvYLxGZ+6DFCSkEeOvH3L R5l5C8XBqGOnyRA7DF3poOTMUm2ULpXJUpKqKHlBSyN4kMq7H0kOIKDQ/YonnpbpDDP lQIz6pHprTtU= Received: (from ache@localhost) by nagual.pp.ru (8.14.2/8.14.2/Submit) id m7R1WMnX083931; Wed, 27 Aug 2008 05:32:22 +0400 (MSD) (envelope-from ache) Date: Wed, 27 Aug 2008 05:32:21 +0400 From: Andrey Chernov To: Gabor Kovesdan Message-ID: <20080827013221.GA82176@nagual.pp.ru> Mail-Followup-To: Andrey Chernov , Gabor Kovesdan , hackers@freebsd.org, Max Khon , dougb@freebsd.org, krion@freebsd.org, current@freebsd.org References: <48B44A7D.3070108@kovesdan.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48B44A7D.3070108@kovesdan.org> User-Agent: Mutt/1.5.18 (2008-05-17) X-Mailman-Approved-At: Wed, 27 Aug 2008 02:22:27 +0000 Cc: current@freebsd.org, Max Khon , hackers@freebsd.org, krion@freebsd.org, dougb@freebsd.org Subject: Re: CFT: BSD grep X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Aug 2008 01:48:46 -0000 On Tue, Aug 26, 2008 at 08:25:01PM +0200, Gabor Kovesdan wrote: > Hello all, > > I've reviewed BSD grep based on your comments and the bug reports I > received. The new version is committed to the ports tree as > textproc/bsdgrep and there is a base patch available: > http://kovesdan.org/patches/grep-base.diff Just from quick looking at the sources... This code looks suspicious: wend = sscanf(&l->dat[pmatch.rm_eo], "%lc", &wend); Perhaps it should be if (sscanf(&l->dat[pmatch.rm_eo], "%lc", &wend) != 1) r = REG_NOMATCH; The next thing is that perhaps each r = REG_NOMATCH; case should be isolated from others in this block (with "else if"?) F.e. failing mbstowcs() can leave buffer for sscanf() in junk. wbegin = grep_malloc(mbstowcs(NULL, l->dat, pmatch.rm_so)); grep_malloc() here could terminate program for invalid mbstowcs() sequence, but really must set only r = REG_NOMATCH; Think about files which, for various reasons, may contain not only valid MB sequences. fgrepcomp() uses toupper()/tolower() while should use wide chars analogs (MB chars can be in the pattern too). There are also many other places where pattern treated as single chars one, fastcomp() etc. grep_cmp() compares single chars toupper(data[]) too. There must be no plain ctype usage in the whole data _and_ pattern handling code. -- http://ache.pp.ru/