Repository navigation
Conversation
larsewi
left a comment
There was a problem hiding this comment.
Please separate each bug fix into their own commits with a changelog.
Covers the current behaviour, before refactoring them. Ticket: ENT-14276 Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FuzzySetMatch() now returns -1 instead of the strncmp() result when a prefix does not match. All callers only compare the result to 0. Ticket: ENT-14276 Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ticket: ENT-14276 Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ticket: ENT-14276 Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ticket: ENT-14276 Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ticket: ENT-14276 Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FuzzySetMatch() now determines the notation of the pattern (prefix, CIDR or range) and calls the matching helper. Ticket: ENT-14276 Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It now splits host and port first and determines the address type afterwards, instead of doing both in each branch. Ticket: ENT-14276 Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was never defined. Ticket: ENT-14276 Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Groups without a range, e.g. "fe80", were parsed as decimal, so "fe80:1-3:0:0:0:0:0:1" matched "fe81:2:0:0:0:0:0:1". Changelog: Title Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"2001:10-20:0:0:0:0:0:1" did not match "2001:10:0:0:0:0:0:1". Changelog: Title Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Neither in the pattern nor in the address, so "2001:db8:1-5::1" never matched "2001:db8:3::1". Invalid groups are now rejected too. Changelog: Title Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When an octet failed to parse, the value of the previous octet was compared instead, so "10.x.0.1-50" matched "10.10.0.25". Changelog: Title Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The address was never validated, so an uninitialized address was compared, and e.g. "bogus/0" matched every address. Changelog: Title Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FuzzyMatchParse() always returned true. It now uses the same parsers as FuzzySetMatch(), including for CIDR patterns. Changelog: Title Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FuzzyHostMatch() read before the start of its buffer when the host name was empty or only digits. Only visible with ASan/valgrind. Changelog: Title Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ParseHostPort() classified e.g. "1password.com" as an IPv4 address. It now uses inet_pton(). Changelog: Title Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There is nothing fuzzy about them. IPRangeMatch() and HostRangeMatch() now return true on match, like StringMatch(), instead of 0. Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The acl argument is always dereferenced. Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Victor Moene <victor.moene@northern.tech> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| (address[len] == '\0' || address[len] == '.'); | ||
| } | ||
|
|
||
| static bool MatchIPv4CIDR(const char *pattern, const char *address) |
craigcomstock
left a comment
There was a problem hiding this comment.
some comments, but looks good to me!
| * | ||
| * @return false if the input is empty, has invalid digits or exceeds max | ||
| */ | ||
| static bool ParseNumber(const char *start, const char *end, int base, |
There was a problem hiding this comment.
I was a little confused at first by [start, end). It feels like a more common argument pair would be const char *string, size_t string_length. I don't see any check for start or end being NULL with an assert. That might be a good idea to sanity check as well as end < start though that will fall through the for loop pretty well.
|
|
||
| while (*count < max) | ||
| { | ||
| const char *sep = memchr(start, ':', end - start); |
There was a problem hiding this comment.
maybe an assert that end is greater than start would be wise?
|
|
||
| if (strstr(gap + 1, "::") != NULL) | ||
| { | ||
| return false; // More than one "::" (or ":::") |
There was a problem hiding this comment.
maybe log this as an error instead of a comment?
| if (!ParseIPv6Groups(pattern, gap, groups, IPV6_GROUPS - 1, &head_count) || | ||
| !ParseIPv6Groups(gap + 2, end, tail, IPV6_GROUPS - 1 - head_count, &tail_count)) | ||
| { | ||
| return false; |
There was a problem hiding this comment.
maybe log an error here saying what is wrong and what the input was.
| if (!ParseNumber(start, end, 10, 255, &value) || | ||
| value < octets[i].from || value > octets[i].to) | ||
| { | ||
| /* address has fewer octets than the pattern: no match */ |
There was a problem hiding this comment.
would it be nice to include this comment as an error log message?
| Log(LOG_LEVEL_DEBUG, "Unequal"); | ||
| return false; | ||
| } | ||
| return (i + 1 == count); // Address must have at least count octets |
There was a problem hiding this comment.
again here, it seems like logging an error might be a good idea.
| const char *slash = strchr(pattern, '/'); | ||
| if (slash == NULL) | ||
| { | ||
| return false; |
There was a problem hiding this comment.
do you think it would be useful to log errors about why the parse function fails to aid the user in fixing their pattern or address?
| unsigned char addr[BINARY_ADDR_SIZE]; | ||
| if (inet_pton(family, address, addr) != 1) | ||
| { | ||
| Log(LOG_LEVEL_ERR, "Invalid reference %s: %s", family_name, address); |
There was a problem hiding this comment.
why the word "reference" here and not "address"?
| if (base_len == 0 || base_len == len) | ||
| { | ||
| return 1; | ||
| return 1; // No base name, or no number |
There was a problem hiding this comment.
for these failure cases, should we log why they are failing? maybe error, or maybe verbose level if errors are logged elsewhere. If a general error is logged due to returning 1 maybe that message should say something about "see verbose logs for details".
No description provided.