strncmp usage in ipfw
Brooks Davis
brooks at one-eyed-alien.net
Mon Nov 29 11:24:29 PST 2004
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-ipfw/attachments/20041129/cf13fc3f/attachment.bin
More information about the freebsd-ipfw
mailing list