[monitoring-plugins] check_icmp: Fix sockset.socket{4,6} detection

Alvar Penning git at monitoring-plugins.org
Thu Sep 10 13:40:15 CEST 2026


 Module: monitoring-plugins
 Branch: master
 Commit: c0ccaa55956c9950c26085d1cfd57682cc6d2b46
 Author: Alvar Penning <post at 0x21.biz>
   Date: Wed Sep  9 09:05:07 2026 +0200
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=c0ccaa55

check_icmp: Fix sockset.socket{4,6} detection

The "check_icmp_socket_set sockset" is initialized with ".socket4" and
".socket6" both being set to -1. Later, these values are being
overwritten with the result of socket(2) if "config.need_v{4,6}" is set.

However, not every access guard checked the value correctly. Resulting
in setsockopt(2) calls for -1, as ktrace(1)/kdump(1) demonstrates:

> 18105 check_icmp CALL  setsockopt(-1,0<ip>,4,0x77553bf062f8,8)
> 18105 check_icmp RET   setsockopt -1 errno 9 Bad file descriptor

---

 plugins-root/check_icmp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 538ade85..bbc10819 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -921,7 +921,7 @@ int main(int argc, char **argv) {
 	pledge("stdio inet", NULL);
 #endif // __OpenBSD__
 
-	if (sockset.socket4) {
+	if (sockset.socket4 != -1) {
 		int result = setsockopt(sockset.socket4, SOL_IP, IP_TTL, &config.ttl, sizeof(config.ttl));
 		if (debug) {
 			if (result == -1) {
@@ -932,7 +932,7 @@ int main(int argc, char **argv) {
 		}
 	}
 
-	if (sockset.socket6) {
+	if (sockset.socket6 != -1) {
 		int result = setsockopt(sockset.socket6, SOL_IP, IP_TTL, &config.ttl, sizeof(config.ttl));
 		if (debug) {
 			if (result == -1) {
@@ -1010,10 +1010,10 @@ int main(int argc, char **argv) {
 		   config.number_of_targets, &program_state, config.hosts, config.number_of_hosts,
 		   &overall);
 
-	if (sockset.socket4) {
+	if (sockset.socket4 != -1) {
 		close(sockset.socket4);
 	}
-	if (sockset.socket6) {
+	if (sockset.socket6 != -1) {
 		close(sockset.socket6);
 	}
 



More information about the Commits mailing list