check_icmp: prevent segfault on OpenBSD (#2224)
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Spellcheck / codespell (push) Waiting to run
Tests / Running unit and integrationt tests (push) Waiting to run
Tests / Running rpm build test on almalinux:9 (push) Waiting to run
Tests / Running rpm build test on fedora:latest (push) Waiting to run
Tests / Running rpm build test on rockylinux:8 (push) Waiting to run

* check_icmp: prevent segfault on OpenBSD

This commit adds a sanity check for sockets in
check_icmp.
Previously FD_ISSET segfaulted when a socket value was
-1 (on OpenBSD). The changes here add an explicit
check whether the socket is -1 (and therefore not
set).

---------

Co-authored-by: Lorenz Kästle <lorenz.kaestle@netways.de>
This commit is contained in:
Lorenz Kästle 2026-01-16 02:42:01 +01:00 committed by GitHub
parent 6716001002
commit b58e244cc7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1470,10 +1470,13 @@ static recvfrom_wto_wrapper recvfrom_wto(const check_icmp_socket_set sockset, vo
};
ssize_t ret;
if (FD_ISSET(sockset.socket4, &read_fds)) {
// Test explicitly whether sockets are in use
// this is necessary at least on OpenBSD where FD_ISSET will segfault otherwise
if ((sockset.socket4 != -1) && FD_ISSET(sockset.socket4, &read_fds)) {
ret = recvmsg(sockset.socket4, &hdr, 0);
result.recv_proto = AF_INET;
} else if (FD_ISSET(sockset.socket6, &read_fds)) {
} else if ((sockset.socket6 != -1) && FD_ISSET(sockset.socket6, &read_fds)) {
ret = recvmsg(sockset.socket6, &hdr, 0);
result.recv_proto = AF_INET6;
} else {