Code review comment for lp:~christian-roeller/hipl/whitelisting

Revision history for this message
Christof Mroz (christof-mroz) wrote :

Almost there:

> + assert(strlen(device_name) < sizeof(whitelist[0].if_label));
> + if (whitelist_count < HIP_NETDEV_MAX_WHITE_LIST) {
> + whitelist[whitelist_count].if_index = if_index;
> + strncpy(whitelist[whitelist_count].if_label,
> + device_name, sizeof(whitelist[0].if_label));
> + whitelist_count++;

There's a HIP_ASSERT() macro that takes care of logging violations, and it's
correctly disabled in non-debug builds.

> - /* We should NEVER run out of white list slots!!! */
> - HIP_DIE("Error: ran out of space for white listed interfaces!\n");
> + /* We should NEVER run out of whitelist slots!!! */
> + HIP_DIE("Error: ran out of space for whitelisted interfaces!\n");

I know you didn't introduce the comment, but it's stupid nevertheless.

> - strncpy(ifr.ifr_name, device_name, IF_NAMESIZE);
> + strncpy(ifr.ifr_name, device_name, sizeof(ifr.ifr_name));

Would a HIP_ASSERT be appropriate here as well?

> * @return interface index if the network address is bound to one, zero if
> - * no interface index was found.
> + * no interface index was found.
> */

Unrelated: is zero a valid index, according to netlink? eth0 is, after all.
Changing the return value on failure to a negative number won't hurt
in any case.

> +START_TEST(test_hip_netdev_find_label_for_address_parameters)
> +{
> + struct ifaddrs *myaddrs, *ifa = NULL;
> + char label[IF_NAMESIZE];
> +
> + /* The passed label parameter for the function hip_find_label_for_address
> + * must be at least 1 greater than the found label in the function. So
> + * a size of 1 would be for sure too short to store at least the shortest
> + * label of only 1 character.
> + */
> + char label_too_short[1];
> +
> + getifaddrs(&myaddrs);

You should warn that this test was skipped if getifaddrs() doesn't return anything.
Using mock functions would be more correct, but in this case it's probably not
worth the effort.

review: Needs Fixing

« Back to merge proposal