Skip to content

Commit ffd3ce4

Browse files
CFE-3081: moved check for valid ipv4 as to not accept bogus address when matching /0 range
Ticket: CFE-3081 Changelog: Fixed bug where isipinsubnet() fails to validate bogus IPv4 addresses when checking the 0.0.0.0/0 range
1 parent 381d74d commit ffd3ce4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

libcfnet/addr_lib.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ int FuzzySetMatch(const char *s1, const char *s2)
116116
struct sockaddr_in addr1, addr2;
117117
unsigned long mask;
118118

119+
// Checks that the addr to match is a valid address
120+
// else bogus addresses will always match /0 range
121+
if (inet_pton(AF_INET, s2, &addr2.sin_addr) != 1) {
122+
Log(LOG_LEVEL_ERR, "Invalid reference IPv4: %s", s2);
123+
return -1;
124+
}
125+
119126
address[0] = '\0';
120127
int ret = sscanf(s1, "%16[^/]/%lu", address, &mask);
121128
if (ret != 2 || mask > 32)
@@ -129,7 +136,6 @@ int FuzzySetMatch(const char *s1, const char *s2)
129136
}
130137

131138
inet_pton(AF_INET, address, &addr1.sin_addr);
132-
inet_pton(AF_INET, s2, &addr2.sin_addr);
133139

134140
unsigned long a1 = htonl(addr1.sin_addr.s_addr);
135141
unsigned long a2 = htonl(addr2.sin_addr.s_addr);

tests/acceptance/02_classes/02_functions/isipinsubnet-valid-ip.cf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ bundle agent test
1919
"description" -> { "CFE-3081" }
2020
string => "Test that isipinsubnet() validates IP addresses as valid especially within the 0.0.0.0/0 range";
2121

22-
"test_soft_fail"
23-
string => "any",
24-
meta => { "CFE-3081"};
2522
vars:
2623

2724
"variable_value_from_varible" string => "$(nosuch.variable)";

0 commit comments

Comments
 (0)