From owner-freebsd-ipfw@FreeBSD.ORG Mon Nov 29 19:24:28 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 D9C3516A4CE for ; Mon, 29 Nov 2004 19:24:28 +0000 (GMT) Received: from odin.ac.hmc.edu (Odin.AC.HMC.Edu [134.173.32.75]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9EFA743D1F for ; Mon, 29 Nov 2004 19:24:28 +0000 (GMT) (envelope-from brdavis@odin.ac.hmc.edu) Received: from odin.ac.hmc.edu (localhost.localdomain [127.0.0.1]) by odin.ac.hmc.edu (8.13.0/8.13.0) with ESMTP id iATJPEUr008288 for ; Mon, 29 Nov 2004 11:25:14 -0800 Received: (from brdavis@localhost) by odin.ac.hmc.edu (8.13.0/8.13.0/Submit) id iATJPEYR008287 for ipfw@freebsd.org; Mon, 29 Nov 2004 11:25:14 -0800 Date: Mon, 29 Nov 2004 11:25:14 -0800 From: Brooks Davis To: ipfw@freebsd.org Message-ID: <20041129192514.GA7331@odin.ac.hmc.edu> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="oyUTqETQ0mS9luUI" Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new X-Spam-Status: No, hits=0.0 required=8.0 tests=none autolearn=no version=2.63 X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on odin.ac.hmc.edu Subject: 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: Mon, 29 Nov 2004 19:24:29 -0000 --oyUTqETQ0mS9luUI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 --=20 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 --oyUTqETQ0mS9luUI Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFBq3eZXY6L6fI4GtQRAjViAJ9xlLMhRVB3kvwI+Fbsg+0aiCO45gCgxms2 pTYTwSo7aLVZUgHVMsqr8aw= =RDMx -----END PGP SIGNATURE----- --oyUTqETQ0mS9luUI--