Skip to content

Commit c67db08

Browse files
committed
Fix RBL lookup to handle IPv6-first addrinfo results
1 parent 0fb4aff commit c67db08

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/operators/rbl.cc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,21 @@ bool Rbl::evaluate(Transaction *t, RuleWithActions *rule,
226226
return false;
227227
}
228228

229-
// SonarCloud suggested to use the init-statement to declare "addr" inside the if statement.
230-
// I think that's not good here, because we need that in the else block
231-
const struct sockaddr *addr = info->ai_addr; // NOSONAR
232-
if (addr->sa_family == AF_INET) { // NOSONAR
233-
struct sockaddr_in sin{}; // initialize an empty struct; we don't need port info
234-
memcpy(&sin.sin_addr, addr->sa_data + 2, sizeof(sin.sin_addr));
235-
sin.sin_family = AF_INET;
236-
furtherInfo(&sin, ipStr, t, m_provider);
229+
bool foundIPv4 = false;
230+
for (const struct addrinfo *ai = info; ai != NULL; ai = ai->ai_next) {
231+
const struct sockaddr *addr = ai->ai_addr;
232+
if (addr != NULL && addr->sa_family == AF_INET) {
233+
struct sockaddr_in sin{}; // initialize an empty struct; we don't need port info
234+
memcpy(&sin.sin_addr, addr->sa_data + 2, sizeof(sin.sin_addr));
235+
sin.sin_family = AF_INET;
236+
furtherInfo(&sin, ipStr, t, m_provider);
237+
foundIPv4 = true;
238+
break;
239+
}
237240
}
238-
else {
239-
ms_dbg_a(t, 7, "Unsupported address family: " + std::to_string(addr->sa_family));
241+
242+
if (!foundIPv4) {
243+
ms_dbg_a(t, 7, "Unsupported address family in RBL result list.");
240244
freeaddrinfo(info);
241245
return false;
242246
}

0 commit comments

Comments
 (0)