strncmp usage in ipfw
Luigi Rizzo
rizzo at icir.org
Tue Nov 30 04:19:37 PST 2004
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
More information about the freebsd-ipfw
mailing list