[monitoring-plugins] check_icmp: prevent segfault on OpenBSD (#2224)

GitHub git at monitoring-plugins.org
Fri Jan 16 02:50:13 CET 2026


    Module: monitoring-plugins
    Branch: master
    Commit: b58e244cc76afc0c02a201fbbdd079db02ed841d
    Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
 Committer: GitHub <noreply at github.com>
      Date: Fri Jan 16 02:42:01 2026 +0100
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=b58e244c

check_icmp: prevent segfault on OpenBSD (#2224)

* 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 at netways.de>

---

 plugins-root/check_icmp.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 58d8a545..5bfb5cb5 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -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 {



More information about the Commits mailing list