From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 4 11:11:31 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 E356A1065673; Thu, 4 Sep 2008 11:11:31 +0000 (UTC) (envelope-from gabor@kovesdan.org) Received: from server.mypc.hu (server.mypc.hu [87.229.73.95]) by mx1.freebsd.org (Postfix) with ESMTP id 92C938FC23; Thu, 4 Sep 2008 11:11:31 +0000 (UTC) (envelope-from gabor@kovesdan.org) Received: from localhost (localhost [127.0.0.1]) by server.mypc.hu (Postfix) with ESMTP id C532814D77F0; Thu, 4 Sep 2008 13:11:29 +0200 (CEST) X-Virus-Scanned: amavisd-new at t-hosting.hu Received: from server.mypc.hu ([127.0.0.1]) by localhost (server.mypc.hu [127.0.0.1]) (amavisd-new, port 10024) with LMTP id AhrxXzCtWV6g; Thu, 4 Sep 2008 13:11:27 +0200 (CEST) Received: from [78.131.25.160] (78-131-25-160.pool.hdsnet.hu [78.131.25.160]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by server.mypc.hu (Postfix) with ESMTPSA id D219C14D77EF; Thu, 4 Sep 2008 13:11:26 +0200 (CEST) Message-ID: <48BFC257.2010000@kovesdan.org> Date: Thu, 04 Sep 2008 13:11:19 +0200 From: Gabor Kovesdan User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 To: Andrey Chernov , Gabor Kovesdan , hackers@freebsd.org, Max Khon , dougb@freebsd.org, krion@freebsd.org, current@freebsd.org References: <48B44A7D.3070108@kovesdan.org> <20080827013221.GA82176@nagual.pp.ru> In-Reply-To: <20080827013221.GA82176@nagual.pp.ru> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Thu, 04 Sep 2008 11:27:59 +0000 Cc: 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: Thu, 04 Sep 2008 11:11:32 -0000 Andrey Chernov ha scritto: > 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. > Hello Andrey, thanks for the detailed description of the current deficiencies, I'll fix them soon. I've been busy with moving to another flat, that's why I haven't replied yet, sorry for that. Gábor