Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Nov 2004 04:19:32 -0800
From:      Luigi Rizzo <rizzo@icir.org>
To:        Brooks Davis <brooks@one-eyed-alien.net>
Cc:        ipfw@freebsd.org
Subject:   Re: strncmp usage in ipfw
Message-ID:  <20041130041932.B91746@xorpc.icir.org>
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
References:  <20041129192514.GA7331@odin.ac.hmc.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041130041932.B91746>