From owner-freebsd-ipfw@FreeBSD.ORG Tue Nov 30 12:19:37 2004 Return-Path: Delivered-To: freebsd-ipfw@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 152A716A4CF for ; Tue, 30 Nov 2004 12:19:37 +0000 (GMT) Received: from xorpc.icir.org (xorpc.icir.org [192.150.187.68]) by mx1.FreeBSD.org (Postfix) with ESMTP id EC12543D5A for ; Tue, 30 Nov 2004 12:19:36 +0000 (GMT) (envelope-from rizzo@icir.org) Received: from xorpc.icir.org (localhost [127.0.0.1]) by xorpc.icir.org (8.12.11/8.12.8) with ESMTP id iAUCJaCg091829; Tue, 30 Nov 2004 04:19:36 -0800 (PST) (envelope-from rizzo@xorpc.icir.org) Received: (from rizzo@localhost) by xorpc.icir.org (8.12.11/8.12.3/Submit) id iAUCJW2b091828; Tue, 30 Nov 2004 04:19:32 -0800 (PST) (envelope-from rizzo) Date: Tue, 30 Nov 2004 04:19:32 -0800 From: Luigi Rizzo To: Brooks Davis Message-ID: <20041130041932.B91746@xorpc.icir.org> References: <20041129192514.GA7331@odin.ac.hmc.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <20041129192514.GA7331@odin.ac.hmc.edu>; from brooks@one-eyed-alien.net on Mon, Nov 29, 2004 at 11:25:14AM -0800 cc: ipfw@freebsd.org Subject: Re: strncmp usage in ipfw X-BeenThere: freebsd-ipfw@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: IPFW Technical Discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Nov 2004 12:19:37 -0000 i believe the original, old ipfw code used strncmp() to allow for abbreviations. When i rewrote ipfw2 i did not feel like removing the feature for fear of introducing backward compatibility problems with existing files. However I agree that this introduces a maintainability nightmare and i believe we should move to strcmp(), especially given that with ipfw2 new option names are coming out quite frequently. cheers luigi On Mon, Nov 29, 2004 at 11:25:14AM -0800, Brooks Davis wrote: > The ipfw program uses the following idiom quite a bit: > > char *var; > if (!strncmp(var, "str", strlen(var))) > ... > > I'm pretty sure that in most cases the desired comparison is actually: > > if (!strcmp(var, "str")) > > The program with the first is that all the following strings match: > > "" > "s" > "st" > "str" > > It's remotely possible this was deliberate since we should not see the > "" case and this would allow partial commands, but I'm not sure and this > creates problems with maintainability. For example, if "str" were "ip" > and you added a line above it containing "ip6" you'd always match "ip6" > leaving difficult to spot dead code in the "ip" case. > > Was use of this idiom deliberate or accidental? > > -- Brooks > > -- > Any statement of the form "X is the one, true Y" is FALSE. > PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4