From c1384375bc55c41bc79a1e1bcce57ffee263b52d Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 9 Jan 2026 13:05:25 +0100 Subject: Fix some minor compiler warnings --- plugins/check_snmp.d/check_snmp_helpers.c | 10 ++++++---- plugins/check_snmp.d/check_snmp_helpers.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/check_snmp.d/check_snmp_helpers.c b/plugins/check_snmp.d/check_snmp_helpers.c index f506537a..2dfc88b5 100644 --- a/plugins/check_snmp.d/check_snmp_helpers.c +++ b/plugins/check_snmp.d/check_snmp_helpers.c @@ -36,7 +36,8 @@ int check_snmp_set_thresholds(const char *threshold_string, check_snmp_test_unit threshold_string++; } - for (char *ptr = strtok(threshold_string, ", "); ptr != NULL; + char *thr_string_copy = strdup(threshold_string); + for (char *ptr = strtok(thr_string_copy, ", "); ptr != NULL; ptr = strtok(NULL, ", "), tu_index++) { if (tu_index > max_test_units) { @@ -64,6 +65,7 @@ int check_snmp_set_thresholds(const char *threshold_string, check_snmp_test_unit } } + free(thr_string_copy); } else { // Single value // only valid for the first test unit @@ -843,8 +845,8 @@ char *_np_state_calculate_location_prefix(void) { * Sets variables. Generates filename. Returns np_state_key. die with * UNKNOWN if exception */ -state_key np_enable_state(char *keyname, int expected_data_version, char *plugin_name, int argc, - char **argv) { +state_key np_enable_state(char *keyname, int expected_data_version, const char *plugin_name, + int argc, char **argv) { state_key *this_state = (state_key *)calloc(1, sizeof(state_key)); if (this_state == NULL) { die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); @@ -869,7 +871,7 @@ state_key np_enable_state(char *keyname, int expected_data_version, char *plugin tmp_char++; } this_state->name = temp_keyname; - this_state->plugin_name = plugin_name; + this_state->plugin_name = (char *)plugin_name; this_state->data_version = expected_data_version; this_state->state_data = NULL; diff --git a/plugins/check_snmp.d/check_snmp_helpers.h b/plugins/check_snmp.d/check_snmp_helpers.h index 0f7780b1..95b361ac 100644 --- a/plugins/check_snmp.d/check_snmp_helpers.h +++ b/plugins/check_snmp.d/check_snmp_helpers.h @@ -66,6 +66,6 @@ typedef struct state_key_struct { } state_key; state_data *np_state_read(state_key stateKey); -state_key np_enable_state(char *keyname, int expected_data_version, char *plugin_name, int argc, - char **argv); +state_key np_enable_state(char *keyname, int expected_data_version, const char *plugin_name, + int argc, char **argv); void np_state_write_string(state_key stateKey, time_t timestamp, char *stringToStore); -- cgit v1.2.3-74-g34f1 From 544ea5bf954abd3ba6bb1b3ec277539dd53c94b9 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 9 Jan 2026 13:09:46 +0100 Subject: Fix error message formatting --- plugins/check_curl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index e7737c7c..0e84b96c 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -787,7 +787,7 @@ redir_wrapper redir(curlhelp_write_curlbuf *header_buf, const check_curl_config strcat(new_url, "?"); strcat(new_url, query_str); }else{ - die(STATE_UNKNOWN, _("HTTP UNKNOWN - No space to add query part of size %d to the buffer, buffer has remaining size %d"), query_str_len , current_len ); + die(STATE_UNKNOWN, _("HTTP UNKNOWN - No space to add query part of size %zu to the buffer, buffer has remaining size %zu"), query_str_len , current_len ); } } -- cgit v1.2.3-74-g34f1 From bbc0c8b29fdbefead8b49bc0bd77193f6fc83a1a Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 9 Jan 2026 13:10:23 +0100 Subject: check_curl: clang-format --- plugins/check_curl.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 0e84b96c..1dec8a2a 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c @@ -775,19 +775,23 @@ redir_wrapper redir(curlhelp_write_curlbuf *header_buf, const check_curl_config /* missing components have null,null in their UriTextRangeA * add query parameters if they exist. */ - if (uri.query.first && uri.query.afterLast){ - // Ensure we have space for '?' + query_str + '\0' ahead of time, instead of calling strncat twice + if (uri.query.first && uri.query.afterLast) { + // Ensure we have space for '?' + query_str + '\0' ahead of time, instead of calling strncat + // twice size_t current_len = strlen(new_url); size_t remaining_space = DEFAULT_BUFFER_SIZE - current_len - 1; - const char* query_str = uri_string(uri.query, buf, DEFAULT_BUFFER_SIZE); + const char *query_str = uri_string(uri.query, buf, DEFAULT_BUFFER_SIZE); size_t query_str_len = strlen(query_str); if (remaining_space >= query_str_len + 1) { strcat(new_url, "?"); strcat(new_url, query_str); - }else{ - die(STATE_UNKNOWN, _("HTTP UNKNOWN - No space to add query part of size %zu to the buffer, buffer has remaining size %zu"), query_str_len , current_len ); + } else { + die(STATE_UNKNOWN, + _("HTTP UNKNOWN - No space to add query part of size %zu to the buffer, buffer has " + "remaining size %zu"), + query_str_len, current_len); } } @@ -1501,8 +1505,8 @@ void print_help(void) { printf(" %s\n", "-I, --IP-address=ADDRESS"); printf(" %s\n", "IP address or name (use numeric address if possible to bypass DNS lookup)."); - printf(" %s\n", - "This overwrites the network address of the target while leaving everything else (HTTP headers) as they are"); + printf(" %s\n", "This overwrites the network address of the target while leaving everything " + "else (HTTP headers) as they are"); printf(" %s\n", "-p, --port=INTEGER"); printf(" %s", _("Port number (default: ")); printf("%d)\n", HTTP_PORT); @@ -1566,7 +1570,8 @@ void print_help(void) { printf(" %s\n", _("String to expect in the content")); printf(" %s\n", "-u, --url=PATH"); printf(" %s\n", _("URL to GET or POST (default: /)")); - printf(" %s\n", _("This is the part after the address in a URL, so for \"https://example.com/index.html\" it would be '-u /index.html'")); + printf(" %s\n", _("This is the part after the address in a URL, so for " + "\"https://example.com/index.html\" it would be '-u /index.html'")); printf(" %s\n", "-P, --post=STRING"); printf(" %s\n", _("URL decoded http POST data")); printf(" %s\n", @@ -1712,7 +1717,8 @@ void print_help(void) { printf(" %s\n", _("It is recommended to use an environment proxy like:")); printf(" %s\n", _("https_proxy=http://192.168.100.35:3128 ./check_curl -H www.verisign.com -S")); - printf(" %s\n", _("legacy proxy requests in check_http style might still work, but are frowned upon, so DONT:")); + printf(" %s\n", _("legacy proxy requests in check_http style might still work, but are frowned " + "upon, so DONT:")); printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u https://www.verisign.com/ -S -j " "CONNECT -H www.verisign.com ")); printf(" %s\n", _("all these options are needed: -I -p -u " -- cgit v1.2.3-74-g34f1 From 35a13449955a969f10f74ac9cab9fed4531a1ca7 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 9 Jan 2026 13:12:31 +0100 Subject: check_curl: fix pointer type --- plugins/check_curl.d/check_curl_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/check_curl.d/check_curl_helpers.c b/plugins/check_curl.d/check_curl_helpers.c index 7be781fc..5af00973 100644 --- a/plugins/check_curl.d/check_curl_helpers.c +++ b/plugins/check_curl.d/check_curl_helpers.c @@ -1214,7 +1214,7 @@ mp_subcheck check_curl_certificate_checks(CURL *curl, X509 *cert, int warn_days_ cert_ptr_union cert_ptr = {0}; cert_ptr.to_info = NULL; - CURLcode res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_info); + CURLcode res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_certinfo); if (!res && cert_ptr.to_info) { # ifdef USE_OPENSSL /* We have no OpenSSL in libcurl, but we can use OpenSSL for X509 cert -- cgit v1.2.3-74-g34f1 From f15029d85694ce2bb4cbde9c441fe55d63263b0c Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 9 Jan 2026 13:41:28 +0100 Subject: check_icmp: fix some compiler warnings (and maybe bugs) --- plugins-root/check_icmp.c | 53 ++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 35cae3ed..58d8a545 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -55,7 +55,7 @@ const char *email = "devel@monitoring-plugins.org"; #include #if defined(SIOCGIFADDR) -#include +# include #endif /* SIOCGIFADDR */ #include #include @@ -1782,6 +1782,7 @@ static void set_source_ip(char *arg, const int icmp_sock, sa_family_t addr_famil /* TODO: Move this to netutils.c and also change check_dhcp to use that. */ static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) { // TODO: Rewrite this so the function return an error and we exit somewhere else + struct sockaddr_in ip_address; ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy #if defined(SIOCGIFADDR) @@ -1797,6 +1798,9 @@ static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) { memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address)); #else + // fake operation to make the compiler happy + (void)icmp_sock; + (void)ifname; errno = 0; crash("Cannot get interface IP address on this platform."); @@ -2046,7 +2050,7 @@ unsigned short icmp_checksum(uint16_t *packet, size_t packet_size) { /* mop up the occasional odd byte */ if (packet_size == 1) { - sum += *((uint8_t *)packet - 1); + sum += *((uint8_t *)packet); } sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ @@ -2245,7 +2249,7 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes, * round trip jitter, but double the impact to latency * then add 10 for protocol latencies (in milliseconds). */ - EffectiveLatency = ((double)rta / 1000) + target.jitter * 2 + 10; + EffectiveLatency = ((double)rta / 1000) + (target.jitter * 2) + 10; double R; if (EffectiveLatency < 160) { @@ -2404,25 +2408,32 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes, if (modes.score_mode) { mp_subcheck sc_score = mp_subcheck_init(); sc_score = mp_set_subcheck_default_state(sc_score, STATE_OK); - xasprintf(&sc_score.output, "Score %f", score); - - if (score <= crit.score) { - sc_score = mp_set_subcheck_state(sc_score, STATE_CRITICAL); - xasprintf(&sc_score.output, "%s <= %f", sc_score.output, crit.score); - } else if (score <= warn.score) { - sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING); - xasprintf(&sc_score.output, "%s <= %f", sc_score.output, warn.score); - } - if (packet_loss < 100) { - mp_perfdata pd_score = perfdata_init(); - xasprintf(&pd_score.label, "%sscore", address); - pd_score.value = mp_create_pd_value(score); - pd_score.warn = mp_range_set_end(pd_score.warn, mp_create_pd_value(warn.score)); - pd_score.crit = mp_range_set_end(pd_score.crit, mp_create_pd_value(crit.score)); - pd_score.min = mp_create_pd_value(0); - pd_score.max = mp_create_pd_value(100); - mp_add_perfdata_to_subcheck(&sc_score, pd_score); + if (target.icmp_recv > 1) { + xasprintf(&sc_score.output, "Score %f", score); + + if (score <= crit.score) { + sc_score = mp_set_subcheck_state(sc_score, STATE_CRITICAL); + xasprintf(&sc_score.output, "%s <= %f", sc_score.output, crit.score); + } else if (score <= warn.score) { + sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING); + xasprintf(&sc_score.output, "%s <= %f", sc_score.output, warn.score); + } + + if (packet_loss < 100) { + mp_perfdata pd_score = perfdata_init(); + xasprintf(&pd_score.label, "%sscore", address); + pd_score.value = mp_create_pd_value(score); + pd_score.warn = mp_range_set_end(pd_score.warn, mp_create_pd_value(warn.score)); + pd_score.crit = mp_range_set_end(pd_score.crit, mp_create_pd_value(crit.score)); + pd_score.min = mp_create_pd_value(0); + pd_score.max = mp_create_pd_value(100); + mp_add_perfdata_to_subcheck(&sc_score, pd_score); + } + + } else { + // score mode disabled due to not enough received packages + xasprintf(&sc_score.output, "Score mode disabled, not enough packets received"); } mp_add_subcheck_to_subcheck(&result, sc_score); -- cgit v1.2.3-74-g34f1 From db0349ae13af260687347064b71127e53b03b0b0 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 9 Jan 2026 14:03:32 +0100 Subject: parse_ini: correct string length --- lib/parse_ini.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/parse_ini.c b/lib/parse_ini.c index db337622..196cac79 100644 --- a/lib/parse_ini.c +++ b/lib/parse_ini.c @@ -352,15 +352,17 @@ static int add_option(FILE *filePointer, np_arg_list **optlst) { optnew->next = NULL; read_pos = 0; - optnew->arg = malloc(cfg_len + 1); + size_t arg_length = cfg_len + 1; + optnew->arg = malloc(arg_length); /* 1-character params needs only one dash */ if (opt_len == 1) { - strncpy(&optnew->arg[read_pos], "-", 1); + strncpy(&optnew->arg[read_pos], "-", arg_length); read_pos += 1; } else { - strncpy(&optnew->arg[read_pos], "--", 2); + strncpy(&optnew->arg[read_pos], "--", arg_length); read_pos += 2; } + strncpy(&optnew->arg[read_pos], optptr, opt_len); read_pos += opt_len; if (value) { -- cgit v1.2.3-74-g34f1 From 7484fcc2606fe1e49dff1ab5f24a69290786b78d Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 9 Jan 2026 14:08:41 +0100 Subject: Fix PS_FORMAT --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index abd90413..7361434a 100644 --- a/configure.ac +++ b/configure.ac @@ -810,7 +810,7 @@ elif ps axwo 'stat comm vsz rss user uid pid ppid etime args' 2>/dev/null | \ then ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]" ac_cv_ps_command="$PATH_TO_PS axwo 'stat uid pid ppid vsz rss pcpu etime comm args'" - ac_cv_ps_format="%s %u %d %d %d %d %f %s %s %n" + ac_cv_ps_format="%s %d %d %d %d %d %f %s %s %n" ac_cv_ps_cols=10 AC_MSG_RESULT([$ac_cv_ps_command]) -- cgit v1.2.3-74-g34f1