by Animats · 11y ago · 0 comments
https://git.openswitch.net/cgit/openswitch/ops-arpmgrd/tree/...
/* Build hash key for a given vrf name and ip address */
static int
get_hash_key(char* vrf_name, char *ip, char *key)
{
sprintf(key, "%s-%s", vrf_name, ip);
return strlen(key);
} /* get_hash_key */
What could possibly go wrong?Definitely not thinking hard about security over there.
Just check Herb Sutter's talk at CppCon 2015, to the question who uses static analyzers, about 1% of the audience said yes.
But, what contexts is this function used in? Is it supposed to be one-way at all? If not, then this is just a simple way of distributing vrf/ip pairs into buckets. Still smells funny, though.
EDIT: This comment looks like I'm defending the implementation here. I'm not. Seems like it'd me more uniform to just add the bytes in the vrf/IP pair and mod them with something. Seeing a hyphen in the format string of sprintf() is really weird, considering that just he string's length is being used.
Again, assuming this is in no way security-related, then this is just a general, run-of-the-mill WTF.
I didn't even go looking for bad code. I was just curious to see what language they were using. This was near the top of the first file I looked at.
The code looks like C code circa 1990. If a first glance turned up this, what else bad is in there?
In a review, I'd call out requirements for buffer overflow detection outside this function.