Gracefully handle IPv6 addresses in blocklist.conf#759
Conversation
…cpy, and don't error if blocklist uses IPv6 subnet/IP
…into phillip/handle-blocklist-ipv6
lib/blocklist.c
Outdated
| // get length of string including the null-byte | ||
| int length = strlen(ip) + 1; | ||
| // don't modify the input string | ||
| char *new_str = strndup(ip, length); |
There was a problem hiding this comment.
I don't really understand the intent behind calling strlen and then passing that into strndup. This feels equivalent to using strdup. If you want to have a limited length, we should use strndup and check that the length is below a certain size using strnlen. Otherwise, we might as well just use strdup.
There was a problem hiding this comment.
Yeah, not sure what I was thinking, strdup looks ideal for this.
lib/blocklist.c
Outdated
| // don't modify the input string | ||
| char *new_str = strndup(ip, length); | ||
| // check if there's a subnet maskChar | ||
| char *maskChar = strchr(new_str, '/'); |
There was a problem hiding this comment.
Can you use one variable naming type in this function? We have both new_str and maskChar? :) I believe that the ZMap style guide says to use mask_char.
There was a problem hiding this comment.
😬 yikes yep, ofc
|
@zakird I've addressed your comments, re-tested on the |
Fixes #756
Changes
Testing
Tested that IPv4 addresses or subnets didn't trigger a
log_fatalTested with the following IPv6 tests
With subnet mask
With compressed IPv6 address
With uncompressed IPv6 address