repsheet/librepsheet — pull request #23 by yippibrian (2014-12-04 22:06:42+00:00)
Title: CIDR fixes and test improvements.

I found some bugs with librepsheet CIDR processing:

1) strtok processing was broken by passing NULL returns to strtol, causing crashes if the cidr value did not contain characters looked for like "/".
2) librepsheet considered a cidr IP address of less than 8 characters to be a bad value. However, an IP like 1.1.1.1 only is 7 characters long, so now code fixed to check if less than 7 characters.
3) In src/blacklist.c and src/whitelist.c I changed "if (cidr_contains(block,actor))" to "if (cidr_contains(block,actor) > 0)". Even though the error codes like BAD_ADDRESS BAD_CIDR_BLOCK are defined to be negative values, the test was passing as if the IP was contained when an IP returned these error codes.
4) I added tests that show these problems. The test all now pass, but if you only apply the part of the patch in the test subdirectory you can see the failures on master.

In addition, I made a minor change to the various teardown functions in the tests directory to set the reply and context pointers to NULL after calling free() on them. Otherwise the tests were crashing when I tried running them after setting the libcheck specific CK_FORK environment variable as follows:

export CK_FORK=no

This is useful to do when debugging test_running with gdb since it avoids forking and makes it easier to debug problems in the tests.