summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2026-01-09 14:18:31 +0100
committerGitHub <noreply@github.com>2026-01-09 14:18:31 +0100
commitf694f4cd4dfead0da6feab04d92335d9bbe185b6 (patch)
treecd48ccd1fdac7a2b08eb0351fd95d2f6770a2277
parentd13413916e72a6d564c796692e1233b92962d58c (diff)
parent7484fcc2606fe1e49dff1ab5f24a69290786b78d (diff)
downloadmonitoring-plugins-f694f4cd4dfead0da6feab04d92335d9bbe185b6.tar.gz
Merge pull request #2218 from RincewindsHat/fix/compiler_warnings
Fix some minor compiler warnings
-rw-r--r--configure.ac2
-rw-r--r--lib/parse_ini.c8
-rw-r--r--plugins-root/check_icmp.c53
-rw-r--r--plugins/check_curl.c24
-rw-r--r--plugins/check_curl.d/check_curl_helpers.c2
-rw-r--r--plugins/check_snmp.d/check_snmp_helpers.c10
-rw-r--r--plugins/check_snmp.d/check_snmp_helpers.h4
7 files changed, 62 insertions, 41 deletions
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 | \
810then 810then
811 ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]" 811 ac_cv_ps_varlist="[procstat,&procuid,&procpid,&procppid,&procvsz,&procrss,&procpcpu,procetime,procprog,&pos]"
812 ac_cv_ps_command="$PATH_TO_PS axwo 'stat uid pid ppid vsz rss pcpu etime comm args'" 812 ac_cv_ps_command="$PATH_TO_PS axwo 'stat uid pid ppid vsz rss pcpu etime comm args'"
813 ac_cv_ps_format="%s %u %d %d %d %d %f %s %s %n" 813 ac_cv_ps_format="%s %d %d %d %d %d %f %s %s %n"
814 ac_cv_ps_cols=10 814 ac_cv_ps_cols=10
815 AC_MSG_RESULT([$ac_cv_ps_command]) 815 AC_MSG_RESULT([$ac_cv_ps_command])
816 816
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) {
352 optnew->next = NULL; 352 optnew->next = NULL;
353 353
354 read_pos = 0; 354 read_pos = 0;
355 optnew->arg = malloc(cfg_len + 1); 355 size_t arg_length = cfg_len + 1;
356 optnew->arg = malloc(arg_length);
356 /* 1-character params needs only one dash */ 357 /* 1-character params needs only one dash */
357 if (opt_len == 1) { 358 if (opt_len == 1) {
358 strncpy(&optnew->arg[read_pos], "-", 1); 359 strncpy(&optnew->arg[read_pos], "-", arg_length);
359 read_pos += 1; 360 read_pos += 1;
360 } else { 361 } else {
361 strncpy(&optnew->arg[read_pos], "--", 2); 362 strncpy(&optnew->arg[read_pos], "--", arg_length);
362 read_pos += 2; 363 read_pos += 2;
363 } 364 }
365
364 strncpy(&optnew->arg[read_pos], optptr, opt_len); 366 strncpy(&optnew->arg[read_pos], optptr, opt_len);
365 read_pos += opt_len; 367 read_pos += opt_len;
366 if (value) { 368 if (value) {
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";
55 55
56#include <sys/time.h> 56#include <sys/time.h>
57#if defined(SIOCGIFADDR) 57#if defined(SIOCGIFADDR)
58#include <sys/ioctl.h> 58# include <sys/ioctl.h>
59#endif /* SIOCGIFADDR */ 59#endif /* SIOCGIFADDR */
60#include <errno.h> 60#include <errno.h>
61#include <signal.h> 61#include <signal.h>
@@ -1782,6 +1782,7 @@ static void set_source_ip(char *arg, const int icmp_sock, sa_family_t addr_famil
1782/* TODO: Move this to netutils.c and also change check_dhcp to use that. */ 1782/* TODO: Move this to netutils.c and also change check_dhcp to use that. */
1783static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) { 1783static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) {
1784 // TODO: Rewrite this so the function return an error and we exit somewhere else 1784 // TODO: Rewrite this so the function return an error and we exit somewhere else
1785
1785 struct sockaddr_in ip_address; 1786 struct sockaddr_in ip_address;
1786 ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy 1787 ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy
1787#if defined(SIOCGIFADDR) 1788#if defined(SIOCGIFADDR)
@@ -1797,6 +1798,9 @@ static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) {
1797 1798
1798 memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address)); 1799 memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address));
1799#else 1800#else
1801 // fake operation to make the compiler happy
1802 (void)icmp_sock;
1803
1800 (void)ifname; 1804 (void)ifname;
1801 errno = 0; 1805 errno = 0;
1802 crash("Cannot get interface IP address on this platform."); 1806 crash("Cannot get interface IP address on this platform.");
@@ -2046,7 +2050,7 @@ unsigned short icmp_checksum(uint16_t *packet, size_t packet_size) {
2046 2050
2047 /* mop up the occasional odd byte */ 2051 /* mop up the occasional odd byte */
2048 if (packet_size == 1) { 2052 if (packet_size == 1) {
2049 sum += *((uint8_t *)packet - 1); 2053 sum += *((uint8_t *)packet);
2050 } 2054 }
2051 2055
2052 sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ 2056 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,
2245 * round trip jitter, but double the impact to latency 2249 * round trip jitter, but double the impact to latency
2246 * then add 10 for protocol latencies (in milliseconds). 2250 * then add 10 for protocol latencies (in milliseconds).
2247 */ 2251 */
2248 EffectiveLatency = ((double)rta / 1000) + target.jitter * 2 + 10; 2252 EffectiveLatency = ((double)rta / 1000) + (target.jitter * 2) + 10;
2249 2253
2250 double R; 2254 double R;
2251 if (EffectiveLatency < 160) { 2255 if (EffectiveLatency < 160) {
@@ -2404,25 +2408,32 @@ mp_subcheck evaluate_target(ping_target target, check_icmp_mode_switches modes,
2404 if (modes.score_mode) { 2408 if (modes.score_mode) {
2405 mp_subcheck sc_score = mp_subcheck_init(); 2409 mp_subcheck sc_score = mp_subcheck_init();
2406 sc_score = mp_set_subcheck_default_state(sc_score, STATE_OK); 2410 sc_score = mp_set_subcheck_default_state(sc_score, STATE_OK);
2407 xasprintf(&sc_score.output, "Score %f", score);
2408
2409 if (score <= crit.score) {
2410 sc_score = mp_set_subcheck_state(sc_score, STATE_CRITICAL);
2411 xasprintf(&sc_score.output, "%s <= %f", sc_score.output, crit.score);
2412 } else if (score <= warn.score) {
2413 sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING);
2414 xasprintf(&sc_score.output, "%s <= %f", sc_score.output, warn.score);
2415 }
2416 2411
2417 if (packet_loss < 100) { 2412 if (target.icmp_recv > 1) {
2418 mp_perfdata pd_score = perfdata_init(); 2413 xasprintf(&sc_score.output, "Score %f", score);
2419 xasprintf(&pd_score.label, "%sscore", address); 2414
2420 pd_score.value = mp_create_pd_value(score); 2415 if (score <= crit.score) {
2421 pd_score.warn = mp_range_set_end(pd_score.warn, mp_create_pd_value(warn.score)); 2416 sc_score = mp_set_subcheck_state(sc_score, STATE_CRITICAL);
2422 pd_score.crit = mp_range_set_end(pd_score.crit, mp_create_pd_value(crit.score)); 2417 xasprintf(&sc_score.output, "%s <= %f", sc_score.output, crit.score);
2423 pd_score.min = mp_create_pd_value(0); 2418 } else if (score <= warn.score) {
2424 pd_score.max = mp_create_pd_value(100); 2419 sc_score = mp_set_subcheck_state(sc_score, STATE_WARNING);
2425 mp_add_perfdata_to_subcheck(&sc_score, pd_score); 2420 xasprintf(&sc_score.output, "%s <= %f", sc_score.output, warn.score);
2421 }
2422
2423 if (packet_loss < 100) {
2424 mp_perfdata pd_score = perfdata_init();
2425 xasprintf(&pd_score.label, "%sscore", address);
2426 pd_score.value = mp_create_pd_value(score);
2427 pd_score.warn = mp_range_set_end(pd_score.warn, mp_create_pd_value(warn.score));
2428 pd_score.crit = mp_range_set_end(pd_score.crit, mp_create_pd_value(crit.score));
2429 pd_score.min = mp_create_pd_value(0);
2430 pd_score.max = mp_create_pd_value(100);
2431 mp_add_perfdata_to_subcheck(&sc_score, pd_score);
2432 }
2433
2434 } else {
2435 // score mode disabled due to not enough received packages
2436 xasprintf(&sc_score.output, "Score mode disabled, not enough packets received");
2426 } 2437 }
2427 2438
2428 mp_add_subcheck_to_subcheck(&result, sc_score); 2439 mp_add_subcheck_to_subcheck(&result, sc_score);
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index e7737c7c..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
775 /* missing components have null,null in their UriTextRangeA 775 /* missing components have null,null in their UriTextRangeA
776 * add query parameters if they exist. 776 * add query parameters if they exist.
777 */ 777 */
778 if (uri.query.first && uri.query.afterLast){ 778 if (uri.query.first && uri.query.afterLast) {
779 // Ensure we have space for '?' + query_str + '\0' ahead of time, instead of calling strncat twice 779 // Ensure we have space for '?' + query_str + '\0' ahead of time, instead of calling strncat
780 // twice
780 size_t current_len = strlen(new_url); 781 size_t current_len = strlen(new_url);
781 size_t remaining_space = DEFAULT_BUFFER_SIZE - current_len - 1; 782 size_t remaining_space = DEFAULT_BUFFER_SIZE - current_len - 1;
782 783
783 const char* query_str = uri_string(uri.query, buf, DEFAULT_BUFFER_SIZE); 784 const char *query_str = uri_string(uri.query, buf, DEFAULT_BUFFER_SIZE);
784 size_t query_str_len = strlen(query_str); 785 size_t query_str_len = strlen(query_str);
785 786
786 if (remaining_space >= query_str_len + 1) { 787 if (remaining_space >= query_str_len + 1) {
787 strcat(new_url, "?"); 788 strcat(new_url, "?");
788 strcat(new_url, query_str); 789 strcat(new_url, query_str);
789 }else{ 790 } else {
790 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 ); 791 die(STATE_UNKNOWN,
792 _("HTTP UNKNOWN - No space to add query part of size %zu to the buffer, buffer has "
793 "remaining size %zu"),
794 query_str_len, current_len);
791 } 795 }
792 } 796 }
793 797
@@ -1501,8 +1505,8 @@ void print_help(void) {
1501 printf(" %s\n", "-I, --IP-address=ADDRESS"); 1505 printf(" %s\n", "-I, --IP-address=ADDRESS");
1502 printf(" %s\n", 1506 printf(" %s\n",
1503 "IP address or name (use numeric address if possible to bypass DNS lookup)."); 1507 "IP address or name (use numeric address if possible to bypass DNS lookup).");
1504 printf(" %s\n", 1508 printf(" %s\n", "This overwrites the network address of the target while leaving everything "
1505 "This overwrites the network address of the target while leaving everything else (HTTP headers) as they are"); 1509 "else (HTTP headers) as they are");
1506 printf(" %s\n", "-p, --port=INTEGER"); 1510 printf(" %s\n", "-p, --port=INTEGER");
1507 printf(" %s", _("Port number (default: ")); 1511 printf(" %s", _("Port number (default: "));
1508 printf("%d)\n", HTTP_PORT); 1512 printf("%d)\n", HTTP_PORT);
@@ -1566,7 +1570,8 @@ void print_help(void) {
1566 printf(" %s\n", _("String to expect in the content")); 1570 printf(" %s\n", _("String to expect in the content"));
1567 printf(" %s\n", "-u, --url=PATH"); 1571 printf(" %s\n", "-u, --url=PATH");
1568 printf(" %s\n", _("URL to GET or POST (default: /)")); 1572 printf(" %s\n", _("URL to GET or POST (default: /)"));
1569 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'")); 1573 printf(" %s\n", _("This is the part after the address in a URL, so for "
1574 "\"https://example.com/index.html\" it would be '-u /index.html'"));
1570 printf(" %s\n", "-P, --post=STRING"); 1575 printf(" %s\n", "-P, --post=STRING");
1571 printf(" %s\n", _("URL decoded http POST data")); 1576 printf(" %s\n", _("URL decoded http POST data"));
1572 printf(" %s\n", 1577 printf(" %s\n",
@@ -1712,7 +1717,8 @@ void print_help(void) {
1712 printf(" %s\n", _("It is recommended to use an environment proxy like:")); 1717 printf(" %s\n", _("It is recommended to use an environment proxy like:"));
1713 printf(" %s\n", 1718 printf(" %s\n",
1714 _("https_proxy=http://192.168.100.35:3128 ./check_curl -H www.verisign.com -S")); 1719 _("https_proxy=http://192.168.100.35:3128 ./check_curl -H www.verisign.com -S"));
1715 printf(" %s\n", _("legacy proxy requests in check_http style might still work, but are frowned upon, so DONT:")); 1720 printf(" %s\n", _("legacy proxy requests in check_http style might still work, but are frowned "
1721 "upon, so DONT:"));
1716 printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u https://www.verisign.com/ -S -j " 1722 printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u https://www.verisign.com/ -S -j "
1717 "CONNECT -H www.verisign.com ")); 1723 "CONNECT -H www.verisign.com "));
1718 printf(" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> " 1724 printf(" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> "
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_
1214 1214
1215 cert_ptr_union cert_ptr = {0}; 1215 cert_ptr_union cert_ptr = {0};
1216 cert_ptr.to_info = NULL; 1216 cert_ptr.to_info = NULL;
1217 CURLcode res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_info); 1217 CURLcode res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &cert_ptr.to_certinfo);
1218 if (!res && cert_ptr.to_info) { 1218 if (!res && cert_ptr.to_info) {
1219# ifdef USE_OPENSSL 1219# ifdef USE_OPENSSL
1220 /* We have no OpenSSL in libcurl, but we can use OpenSSL for X509 cert 1220 /* We have no OpenSSL in libcurl, but we can use OpenSSL for X509 cert
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
36 threshold_string++; 36 threshold_string++;
37 } 37 }
38 38
39 for (char *ptr = strtok(threshold_string, ", "); ptr != NULL; 39 char *thr_string_copy = strdup(threshold_string);
40 for (char *ptr = strtok(thr_string_copy, ", "); ptr != NULL;
40 ptr = strtok(NULL, ", "), tu_index++) { 41 ptr = strtok(NULL, ", "), tu_index++) {
41 42
42 if (tu_index > max_test_units) { 43 if (tu_index > max_test_units) {
@@ -64,6 +65,7 @@ int check_snmp_set_thresholds(const char *threshold_string, check_snmp_test_unit
64 } 65 }
65 } 66 }
66 67
68 free(thr_string_copy);
67 } else { 69 } else {
68 // Single value 70 // Single value
69 // only valid for the first test unit 71 // only valid for the first test unit
@@ -843,8 +845,8 @@ char *_np_state_calculate_location_prefix(void) {
843 * Sets variables. Generates filename. Returns np_state_key. die with 845 * Sets variables. Generates filename. Returns np_state_key. die with
844 * UNKNOWN if exception 846 * UNKNOWN if exception
845 */ 847 */
846state_key np_enable_state(char *keyname, int expected_data_version, char *plugin_name, int argc, 848state_key np_enable_state(char *keyname, int expected_data_version, const char *plugin_name,
847 char **argv) { 849 int argc, char **argv) {
848 state_key *this_state = (state_key *)calloc(1, sizeof(state_key)); 850 state_key *this_state = (state_key *)calloc(1, sizeof(state_key));
849 if (this_state == NULL) { 851 if (this_state == NULL) {
850 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), strerror(errno)); 852 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
869 tmp_char++; 871 tmp_char++;
870 } 872 }
871 this_state->name = temp_keyname; 873 this_state->name = temp_keyname;
872 this_state->plugin_name = plugin_name; 874 this_state->plugin_name = (char *)plugin_name;
873 this_state->data_version = expected_data_version; 875 this_state->data_version = expected_data_version;
874 this_state->state_data = NULL; 876 this_state->state_data = NULL;
875 877
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 {
66} state_key; 66} state_key;
67 67
68state_data *np_state_read(state_key stateKey); 68state_data *np_state_read(state_key stateKey);
69state_key np_enable_state(char *keyname, int expected_data_version, char *plugin_name, int argc, 69state_key np_enable_state(char *keyname, int expected_data_version, const char *plugin_name,
70 char **argv); 70 int argc, char **argv);
71void np_state_write_string(state_key stateKey, time_t timestamp, char *stringToStore); 71void np_state_write_string(state_key stateKey, time_t timestamp, char *stringToStore);