summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-10-29 10:09:00 (GMT)
committerGitHub <noreply@github.com>2023-10-29 10:09:00 (GMT)
commit77e38ac1c025b8431d1834a2c1059f9677c78ab1 (patch)
treeaa8dc016303530e56155826f355cb7e3c3a4ee94
parent2eea6bb2a04bbfb169bac5f0f7c319f998e8ab87 (diff)
parenteead88edda047843b911afd7b63e7decfee306ce (diff)
downloadmonitoring-plugins-77e38ac1c025b8431d1834a2c1059f9677c78ab1.tar.gz
Merge pull request #1953 from RincewindsHat/compiler_warnings-sign-compare
Fixes for -Wsign-compare
-rw-r--r--lib/utils_base.c2
-rw-r--r--lib/utils_base.h2
-rw-r--r--lib/utils_cmd.c3
-rw-r--r--plugins/check_apt.c19
-rw-r--r--plugins/check_by_ssh.c15
-rw-r--r--plugins/check_curl.c13
-rw-r--r--plugins/check_dns.c6
-rw-r--r--plugins/check_http.c2
-rw-r--r--plugins/check_procs.c4
-rw-r--r--plugins/check_snmp.c35
-rw-r--r--plugins/check_tcp.c27
-rw-r--r--plugins/check_ups.c3
-rw-r--r--plugins/negate.c5
-rw-r--r--plugins/runcmd.c3
-rw-r--r--plugins/utils.c10
15 files changed, 80 insertions, 69 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c
index f86efbe..f8592f4 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -37,7 +37,7 @@
37 37
38monitoring_plugin *this_monitoring_plugin=NULL; 38monitoring_plugin *this_monitoring_plugin=NULL;
39 39
40unsigned int timeout_state = STATE_CRITICAL; 40int timeout_state = STATE_CRITICAL;
41unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; 41unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT;
42 42
43bool _np_state_read_file(FILE *); 43bool _np_state_read_file(FILE *);
diff --git a/lib/utils_base.h b/lib/utils_base.h
index 80b8743..9d4dffe 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -65,7 +65,7 @@ bool check_range(double, range *);
65int get_status(double, thresholds *); 65int get_status(double, thresholds *);
66 66
67/* Handle timeouts */ 67/* Handle timeouts */
68extern unsigned int timeout_state; 68extern int timeout_state;
69extern unsigned int timeout_interval; 69extern unsigned int timeout_interval;
70 70
71/* All possible characters in a threshold range */ 71/* All possible characters in a threshold range */
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c
index cfb2073..7957ec1 100644
--- a/lib/utils_cmd.c
+++ b/lib/utils_cmd.c
@@ -390,13 +390,12 @@ cmd_file_read ( char *filename, output *out, int flags)
390void 390void
391timeout_alarm_handler (int signo) 391timeout_alarm_handler (int signo)
392{ 392{
393 size_t i;
394 if (signo == SIGALRM) { 393 if (signo == SIGALRM) {
395 printf (_("%s - Plugin timed out after %d seconds\n"), 394 printf (_("%s - Plugin timed out after %d seconds\n"),
396 state_text(timeout_state), timeout_interval); 395 state_text(timeout_state), timeout_interval);
397 396
398 long maxfd = mp_open_max(); 397 long maxfd = mp_open_max();
399 if(_cmd_pids) for(i = 0; i < maxfd; i++) { 398 if(_cmd_pids) for(long int i = 0; i < maxfd; i++) {
400 if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL); 399 if(_cmd_pids[i] != 0) kill(_cmd_pids[i], SIGKILL);
401 } 400 }
402 401
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index fa982ae..5c0f6e2 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -94,7 +94,7 @@ static int stderr_warning = 0; /* if a cmd issued output on stderr */
94static int exec_warning = 0; /* if a cmd exited non-zero */ 94static int exec_warning = 0; /* if a cmd exited non-zero */
95 95
96int main (int argc, char **argv) { 96int main (int argc, char **argv) {
97 int result=STATE_UNKNOWN, packages_available=0, sec_count=0, i=0; 97 int result=STATE_UNKNOWN, packages_available=0, sec_count=0;
98 char **packages_list=NULL, **secpackages_list=NULL; 98 char **packages_list=NULL, **secpackages_list=NULL;
99 99
100 /* Parse extra opts if any */ 100 /* Parse extra opts if any */
@@ -142,10 +142,11 @@ int main (int argc, char **argv) {
142 qsort(secpackages_list, sec_count, sizeof(char*), cmpstringp); 142 qsort(secpackages_list, sec_count, sizeof(char*), cmpstringp);
143 qsort(packages_list, packages_available-sec_count, sizeof(char*), cmpstringp); 143 qsort(packages_list, packages_available-sec_count, sizeof(char*), cmpstringp);
144 144
145 for(i = 0; i < sec_count; i++) 145 for(int i = 0; i < sec_count; i++)
146 printf("%s (security)\n", secpackages_list[i]); 146 printf("%s (security)\n", secpackages_list[i]);
147
147 if (only_critical == false) { 148 if (only_critical == false) {
148 for(i = 0; i < packages_available - sec_count; i++) 149 for(int i = 0; i < packages_available - sec_count; i++)
149 printf("%s\n", packages_list[i]); 150 printf("%s\n", packages_list[i]);
150 } 151 }
151 } 152 }
@@ -251,7 +252,7 @@ int process_arguments (int argc, char **argv) {
251 252
252/* run an apt-get upgrade */ 253/* run an apt-get upgrade */
253int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist){ 254int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkglist){
254 int i=0, result=STATE_UNKNOWN, regres=0, pc=0, spc=0; 255 int result=STATE_UNKNOWN, regres=0, pc=0, spc=0;
255 struct output chld_out, chld_err; 256 struct output chld_out, chld_err;
256 regex_t ireg, ereg, sreg; 257 regex_t ireg, ereg, sreg;
257 char *cmdline=NULL, rerrbuf[64]; 258 char *cmdline=NULL, rerrbuf[64];
@@ -320,7 +321,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg
320 * we may need to switch to the --print-uris output format, 321 * we may need to switch to the --print-uris output format,
321 * in which case the logic here will slightly change. 322 * in which case the logic here will slightly change.
322 */ 323 */
323 for(i = 0; i < chld_out.lines; i++) { 324 for(size_t i = 0; i < chld_out.lines; i++) {
324 if(verbose){ 325 if(verbose){
325 printf("%s\n", chld_out.line[i]); 326 printf("%s\n", chld_out.line[i]);
326 } 327 }
@@ -353,7 +354,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg
353 stderr_warning=1; 354 stderr_warning=1;
354 result = max_state(result, STATE_WARNING); 355 result = max_state(result, STATE_WARNING);
355 if(verbose){ 356 if(verbose){
356 for(i = 0; i < chld_err.lines; i++) { 357 for(size_t i = 0; i < chld_err.lines; i++) {
357 fprintf(stderr, "%s\n", chld_err.line[i]); 358 fprintf(stderr, "%s\n", chld_err.line[i]);
358 } 359 }
359 } 360 }
@@ -367,7 +368,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount, char ***pkglist, char ***secpkg
367 368
368/* run an apt-get update (needs root) */ 369/* run an apt-get update (needs root) */
369int run_update(void){ 370int run_update(void){
370 int i=0, result=STATE_UNKNOWN; 371 int result=STATE_UNKNOWN;
371 struct output chld_out, chld_err; 372 struct output chld_out, chld_err;
372 char *cmdline; 373 char *cmdline;
373 374
@@ -385,7 +386,7 @@ int run_update(void){
385 } 386 }
386 387
387 if(verbose){ 388 if(verbose){
388 for(i = 0; i < chld_out.lines; i++) { 389 for(size_t i = 0; i < chld_out.lines; i++) {
389 printf("%s\n", chld_out.line[i]); 390 printf("%s\n", chld_out.line[i]);
390 } 391 }
391 } 392 }
@@ -395,7 +396,7 @@ int run_update(void){
395 stderr_warning=1; 396 stderr_warning=1;
396 result = max_state(result, STATE_WARNING); 397 result = max_state(result, STATE_WARNING);
397 if(verbose){ 398 if(verbose){
398 for(i = 0; i < chld_err.lines; i++) { 399 for(size_t i = 0; i < chld_err.lines; i++) {
399 fprintf(stderr, "%s\n", chld_err.line[i]); 400 fprintf(stderr, "%s\n", chld_err.line[i]);
400 } 401 }
401 } 402 }
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 1f5f72d..2a23b39 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -68,7 +68,6 @@ main (int argc, char **argv)
68 char *status_text; 68 char *status_text;
69 int cresult; 69 int cresult;
70 int result = STATE_UNKNOWN; 70 int result = STATE_UNKNOWN;
71 int i;
72 time_t local_time; 71 time_t local_time;
73 FILE *fp = NULL; 72 FILE *fp = NULL;
74 output chld_out, chld_err; 73 output chld_out, chld_err;
@@ -96,7 +95,7 @@ main (int argc, char **argv)
96 /* run the command */ 95 /* run the command */
97 if (verbose) { 96 if (verbose) {
98 printf ("Command: %s\n", commargv[0]); 97 printf ("Command: %s\n", commargv[0]);
99 for (i=1; i<commargc; i++) 98 for (int i = 1; i < commargc; i++)
100 printf ("Argument %i: %s\n", i, commargv[i]); 99 printf ("Argument %i: %s\n", i, commargv[i]);
101 } 100 }
102 101
@@ -110,9 +109,9 @@ main (int argc, char **argv)
110 } 109 }
111 110
112 if (verbose) { 111 if (verbose) {
113 for(i = 0; i < chld_out.lines; i++) 112 for(size_t i = 0; i < chld_out.lines; i++)
114 printf("stdout: %s\n", chld_out.line[i]); 113 printf("stdout: %s\n", chld_out.line[i]);
115 for(i = 0; i < chld_err.lines; i++) 114 for(size_t i = 0; i < chld_err.lines; i++)
116 printf("stderr: %s\n", chld_err.line[i]); 115 printf("stderr: %s\n", chld_err.line[i]);
117 } 116 }
118 117
@@ -122,7 +121,7 @@ main (int argc, char **argv)
122 skip_stderr = chld_err.lines; 121 skip_stderr = chld_err.lines;
123 122
124 /* UNKNOWN or worse if (non-skipped) output found on stderr */ 123 /* UNKNOWN or worse if (non-skipped) output found on stderr */
125 if(chld_err.lines > skip_stderr) { 124 if(chld_err.lines > (size_t)skip_stderr) {
126 printf (_("Remote command execution failed: %s\n"), 125 printf (_("Remote command execution failed: %s\n"),
127 chld_err.line[skip_stderr]); 126 chld_err.line[skip_stderr]);
128 if ( warn_on_stderr ) 127 if ( warn_on_stderr )
@@ -134,8 +133,8 @@ main (int argc, char **argv)
134 /* this is simple if we're not supposed to be passive. 133 /* this is simple if we're not supposed to be passive.
135 * Wrap up quickly and keep the tricks below */ 134 * Wrap up quickly and keep the tricks below */
136 if(!passive) { 135 if(!passive) {
137 if (chld_out.lines > skip_stdout) 136 if (chld_out.lines > (size_t)skip_stdout)
138 for (i = skip_stdout; i < chld_out.lines; i++) 137 for (size_t i = skip_stdout; i < chld_out.lines; i++)
139 puts (chld_out.line[i]); 138 puts (chld_out.line[i]);
140 else 139 else
141 printf (_("%s - check_by_ssh: Remote command '%s' returned status %d\n"), 140 printf (_("%s - check_by_ssh: Remote command '%s' returned status %d\n"),
@@ -156,7 +155,7 @@ main (int argc, char **argv)
156 155
157 local_time = time (NULL); 156 local_time = time (NULL);
158 commands = 0; 157 commands = 0;
159 for(i = skip_stdout; i < chld_out.lines; i++) { 158 for(size_t i = skip_stdout; i < chld_out.lines; i++) {
160 status_text = chld_out.line[i++]; 159 status_text = chld_out.line[i++];
161 if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL) 160 if (i == chld_out.lines || strstr (chld_out.line[i], "STATUS CODE: ") == NULL)
162 die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname); 161 die (STATE_UNKNOWN, _("%s: Error parsing output\n"), progname);
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 153e492..9c0dc34 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -1186,16 +1186,16 @@ int
1186uri_strcmp (const UriTextRangeA range, const char* s) 1186uri_strcmp (const UriTextRangeA range, const char* s)
1187{ 1187{
1188 if (!range.first) return -1; 1188 if (!range.first) return -1;
1189 if (range.afterLast - range.first < strlen (s)) return -1; 1189 if ( (size_t)(range.afterLast - range.first) < strlen (s) ) return -1;
1190 return strncmp (s, range.first, min( range.afterLast - range.first, strlen (s))); 1190 return strncmp (s, range.first, min( (size_t)(range.afterLast - range.first), strlen (s)));
1191} 1191}
1192 1192
1193char* 1193char*
1194uri_string (const UriTextRangeA range, char* buf, size_t buflen) 1194uri_string (const UriTextRangeA range, char* buf, size_t buflen)
1195{ 1195{
1196 if (!range.first) return "(null)"; 1196 if (!range.first) return "(null)";
1197 strncpy (buf, range.first, max (buflen-1, range.afterLast - range.first)); 1197 strncpy (buf, range.first, max (buflen-1, (size_t)(range.afterLast - range.first)));
1198 buf[max (buflen-1, range.afterLast - range.first)] = '\0'; 1198 buf[max (buflen-1, (size_t)(range.afterLast - range.first))] = '\0';
1199 buf[range.afterLast - range.first] = '\0'; 1199 buf[range.afterLast - range.first] = '\0';
1200 return buf; 1200 return buf;
1201} 1201}
@@ -2368,8 +2368,7 @@ remove_newlines (char *s)
2368char * 2368char *
2369get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header) 2369get_header_value (const struct phr_header* headers, const size_t nof_headers, const char* header)
2370{ 2370{
2371 int i; 2371 for(size_t i = 0; i < nof_headers; i++ ) {
2372 for( i = 0; i < nof_headers; i++ ) {
2373 if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) { 2372 if(headers[i].name != NULL && strncasecmp( header, headers[i].name, max( headers[i].name_len, 4 ) ) == 0 ) {
2374 return strndup( headers[i].value, headers[i].value_len ); 2373 return strndup( headers[i].value, headers[i].value_len );
2375 } 2374 }
@@ -2471,7 +2470,7 @@ check_document_dates (const curlhelp_write_curlbuf *header_buf, char (*msg)[DEFA
2471int 2470int
2472get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf) 2471get_content_length (const curlhelp_write_curlbuf* header_buf, const curlhelp_write_curlbuf* body_buf)
2473{ 2472{
2474 int content_length = 0; 2473 size_t content_length = 0;
2475 struct phr_header headers[255]; 2474 struct phr_header headers[255];
2476 size_t nof_headers = 255; 2475 size_t nof_headers = 255;
2477 size_t msglen; 2476 size_t msglen;
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 82dc264..5e20214 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -122,7 +122,7 @@ main (int argc, char **argv)
122 } 122 }
123 123
124 /* scan stdout */ 124 /* scan stdout */
125 for(i = 0; i < chld_out.lines; i++) { 125 for(size_t i = 0; i < chld_out.lines; i++) {
126 if (addresses == NULL) 126 if (addresses == NULL)
127 addresses = malloc(sizeof(*addresses)*10); 127 addresses = malloc(sizeof(*addresses)*10);
128 else if (!(n_addresses % 10)) 128 else if (!(n_addresses % 10))
@@ -197,7 +197,7 @@ main (int argc, char **argv)
197 } 197 }
198 198
199 /* scan stderr */ 199 /* scan stderr */
200 for(i = 0; i < chld_err.lines; i++) { 200 for(size_t i = 0; i < chld_err.lines; i++) {
201 if (verbose) 201 if (verbose)
202 puts(chld_err.line[i]); 202 puts(chld_err.line[i]);
203 203
@@ -241,7 +241,7 @@ main (int argc, char **argv)
241 unsigned long expect_match = (1 << expected_address_cnt) - 1; 241 unsigned long expect_match = (1 << expected_address_cnt) - 1;
242 unsigned long addr_match = (1 << n_addresses) - 1; 242 unsigned long addr_match = (1 << n_addresses) - 1;
243 243
244 for (i=0; i<expected_address_cnt; i++) { 244 for (int i=0; i<expected_address_cnt; i++) {
245 int j; 245 int j;
246 /* check if we get a match on 'raw' ip or cidr */ 246 /* check if we get a match on 'raw' ip or cidr */
247 for (j=0; j<n_addresses; j++) { 247 for (j=0; j<n_addresses; j++) {
diff --git a/plugins/check_http.c b/plugins/check_http.c
index b9d8145..110f118 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -471,7 +471,7 @@ bool process_arguments (int argc, char **argv)
471 free(http_method); 471 free(http_method);
472 http_method = strdup (optarg); 472 http_method = strdup (optarg);
473 char *tmp; 473 char *tmp;
474 if ((tmp = strstr(http_method, ":")) > 0) { 474 if ((tmp = strstr(http_method, ":")) != NULL) {
475 tmp[0] = '\0'; 475 tmp[0] = '\0';
476 http_method = http_method; 476 http_method = http_method;
477 http_method_proxy = ++tmp; 477 http_method_proxy = ++tmp;
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 1637e3e..6e3feae 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -153,7 +153,7 @@ main (int argc, char **argv)
153 int expected_cols = PS_COLS - 1; 153 int expected_cols = PS_COLS - 1;
154 int warn = 0; /* number of processes in warn state */ 154 int warn = 0; /* number of processes in warn state */
155 int crit = 0; /* number of processes in crit state */ 155 int crit = 0; /* number of processes in crit state */
156 int i = 0, j = 0; 156 int i = 0;
157 int result = STATE_UNKNOWN; 157 int result = STATE_UNKNOWN;
158 int ret = 0; 158 int ret = 0;
159 output chld_out, chld_err; 159 output chld_out, chld_err;
@@ -207,7 +207,7 @@ main (int argc, char **argv)
207 } 207 }
208 208
209 /* flush first line: j starts at 1 */ 209 /* flush first line: j starts at 1 */
210 for (j = 1; j < chld_out.lines; j++) { 210 for (size_t j = 1; j < chld_out.lines; j++) {
211 input_line = chld_out.line[j]; 211 input_line = chld_out.line[j];
212 212
213 if (verbose >= 3) 213 if (verbose >= 3)
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 405ede3..7ee9d0c 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -131,7 +131,7 @@ size_t nlabels = 0;
131size_t labels_size = OID_COUNT_STEP; 131size_t labels_size = OID_COUNT_STEP;
132size_t nunits = 0; 132size_t nunits = 0;
133size_t unitv_size = OID_COUNT_STEP; 133size_t unitv_size = OID_COUNT_STEP;
134int numoids = 0; 134size_t numoids = 0;
135int numauthpriv = 0; 135int numauthpriv = 0;
136int numcontext = 0; 136int numcontext = 0;
137int verbose = 0; 137int verbose = 0;
@@ -187,7 +187,8 @@ static char *fix_snmp_range(char *th)
187int 187int
188main (int argc, char **argv) 188main (int argc, char **argv)
189{ 189{
190 int i, len, line, total_oids; 190 int len, total_oids;
191 size_t line;
191 unsigned int bk_count = 0, dq_count = 0; 192 unsigned int bk_count = 0, dq_count = 0;
192 int iresult = STATE_UNKNOWN; 193 int iresult = STATE_UNKNOWN;
193 int result = STATE_UNKNOWN; 194 int result = STATE_UNKNOWN;
@@ -253,14 +254,16 @@ main (int argc, char **argv)
253 if(calculate_rate) { 254 if(calculate_rate) {
254 if (!strcmp(label, "SNMP")) 255 if (!strcmp(label, "SNMP"))
255 label = strdup("SNMP RATE"); 256 label = strdup("SNMP RATE");
256 i=0; 257
258 size_t i = 0;
259
257 previous_state = np_state_read(); 260 previous_state = np_state_read();
258 if(previous_state!=NULL) { 261 if(previous_state!=NULL) {
259 /* Split colon separated values */ 262 /* Split colon separated values */
260 previous_string = strdup((char *) previous_state->data); 263 previous_string = strdup((char *) previous_state->data);
261 while((ap = strsep(&previous_string, ":")) != NULL) { 264 while((ap = strsep(&previous_string, ":")) != NULL) {
262 if(verbose>2) 265 if(verbose>2)
263 printf("State for %d=%s\n", i, ap); 266 printf("State for %zd=%s\n", i, ap);
264 while (i >= previous_size) { 267 while (i >= previous_size) {
265 previous_size += OID_COUNT_STEP; 268 previous_size += OID_COUNT_STEP;
266 previous_value = realloc(previous_value, previous_size * sizeof(*previous_value)); 269 previous_value = realloc(previous_value, previous_size * sizeof(*previous_value));
@@ -273,7 +276,7 @@ main (int argc, char **argv)
273 /* Populate the thresholds */ 276 /* Populate the thresholds */
274 th_warn=warning_thresholds; 277 th_warn=warning_thresholds;
275 th_crit=critical_thresholds; 278 th_crit=critical_thresholds;
276 for (i=0; i<numoids; i++) { 279 for (size_t i = 0; i < numoids; i++) {
277 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; 280 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL;
278 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; 281 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL;
279 /* translate "2:1" to "@1:2" for backwards compatibility */ 282 /* translate "2:1" to "@1:2" for backwards compatibility */
@@ -333,11 +336,11 @@ main (int argc, char **argv)
333 } 336 }
334 337
335 338
336 for (i = 0; i < numcontext; i++) { 339 for (int i = 0; i < numcontext; i++) {
337 command_line[index++] = contextargs[i]; 340 command_line[index++] = contextargs[i];
338 } 341 }
339 342
340 for (i = 0; i < numauthpriv; i++) { 343 for (int i = 0; i < numauthpriv; i++) {
341 command_line[index++] = authpriv[i]; 344 command_line[index++] = authpriv[i];
342 } 345 }
343 346
@@ -348,7 +351,7 @@ main (int argc, char **argv)
348 server_address, 351 server_address,
349 port); 352 port);
350 353
351 for (i = 0; i < numoids; i++) { 354 for (size_t i = 0; i < numoids; i++) {
352 command_line[index++] = oids[i]; 355 command_line[index++] = oids[i];
353 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 356 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
354 } 357 }
@@ -382,7 +385,7 @@ main (int argc, char **argv)
382 if (external_error) { 385 if (external_error) {
383 if (chld_err.lines > 0) { 386 if (chld_err.lines > 0) {
384 printf (_("External command error: %s\n"), chld_err.line[0]); 387 printf (_("External command error: %s\n"), chld_err.line[0]);
385 for (i = 1; i < chld_err.lines; i++) { 388 for (size_t i = 1; i < chld_err.lines; i++) {
386 printf ("%s\n", chld_err.line[i]); 389 printf ("%s\n", chld_err.line[i]);
387 } 390 }
388 } else { 391 } else {
@@ -392,12 +395,14 @@ main (int argc, char **argv)
392 } 395 }
393 396
394 if (verbose) { 397 if (verbose) {
395 for (i = 0; i < chld_out.lines; i++) { 398 for (size_t i = 0; i < chld_out.lines; i++) {
396 printf ("%s\n", chld_out.line[i]); 399 printf ("%s\n", chld_out.line[i]);
397 } 400 }
398 } 401 }
399 402
400 for (line=0, i=0; line < chld_out.lines && i < numoids ; line++, i++) { 403 line = 0;
404 total_oids = 0;
405 for (size_t i = 0; line < chld_out.lines && i < numoids ; line++, i++, total_oids++) {
401 if(calculate_rate) 406 if(calculate_rate)
402 conv = "%.10g"; 407 conv = "%.10g";
403 else 408 else
@@ -410,7 +415,7 @@ main (int argc, char **argv)
410 break; 415 break;
411 416
412 if (verbose > 2) { 417 if (verbose > 2) {
413 printf("Processing oid %i (line %i)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response); 418 printf("Processing oid %zi (line %zi)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response);
414 } 419 }
415 420
416 /* Clean up type array - Sol10 does not necessarily zero it out */ 421 /* Clean up type array - Sol10 does not necessarily zero it out */
@@ -634,7 +639,6 @@ main (int argc, char **argv)
634 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); 639 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1);
635 } 640 }
636 } 641 }
637 total_oids=i;
638 642
639 /* Save state data, as all data collected now */ 643 /* Save state data, as all data collected now */
640 if(calculate_rate) { 644 if(calculate_rate) {
@@ -644,7 +648,7 @@ main (int argc, char **argv)
644 die(STATE_UNKNOWN, _("Cannot malloc")); 648 die(STATE_UNKNOWN, _("Cannot malloc"));
645 649
646 current_length=0; 650 current_length=0;
647 for(i=0; i<total_oids; i++) { 651 for(int i = 0; i < total_oids; i++) {
648 xasprintf(&temp_string,"%.0f",response_value[i]); 652 xasprintf(&temp_string,"%.0f",response_value[i]);
649 if(temp_string==NULL) 653 if(temp_string==NULL)
650 die(STATE_UNKNOWN,_("Cannot asprintf()")); 654 die(STATE_UNKNOWN,_("Cannot asprintf()"));
@@ -687,7 +691,8 @@ process_arguments (int argc, char **argv)
687{ 691{
688 char *ptr; 692 char *ptr;
689 int c = 1; 693 int c = 1;
690 int j = 0, jj = 0, ii = 0; 694 int ii = 0;
695 size_t j = 0, jj = 0;
691 696
692 int option = 0; 697 int option = 0;
693 static struct option longopts[] = { 698 static struct option longopts[] = {
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index a1a14b4..01dd35e 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -70,7 +70,7 @@ static char *server_send = NULL;
70static char *server_quit = NULL; 70static char *server_quit = NULL;
71static char **server_expect; 71static char **server_expect;
72static size_t server_expect_count = 0; 72static size_t server_expect_count = 0;
73static size_t maxbytes = 0; 73static ssize_t maxbytes = 0;
74static char **warn_codes = NULL; 74static char **warn_codes = NULL;
75static size_t warn_codes_count = 0; 75static size_t warn_codes_count = 0;
76static char **crit_codes = NULL; 76static char **crit_codes = NULL;
@@ -102,11 +102,9 @@ int
102main (int argc, char **argv) 102main (int argc, char **argv)
103{ 103{
104 int result = STATE_UNKNOWN; 104 int result = STATE_UNKNOWN;
105 int i;
106 char *status = NULL; 105 char *status = NULL;
107 struct timeval tv; 106 struct timeval tv;
108 struct timeval timeout; 107 struct timeval timeout;
109 size_t len;
110 int match = -1; 108 int match = -1;
111 fd_set rfds; 109 fd_set rfds;
112 110
@@ -121,10 +119,10 @@ main (int argc, char **argv)
121 if(progname != NULL) progname++; 119 if(progname != NULL) progname++;
122 else progname = argv[0]; 120 else progname = argv[0];
123 121
124 len = strlen(progname); 122 size_t prog_name_len = strlen(progname);
125 if(len > 6 && !memcmp(progname, "check_", 6)) { 123 if(prog_name_len > 6 && !memcmp(progname, "check_", 6)) {
126 SERVICE = strdup(progname + 6); 124 SERVICE = strdup(progname + 6);
127 for(i = 0; i < len - 6; i++) 125 for(size_t i = 0; i < prog_name_len - 6; i++)
128 SERVICE[i] = toupper(SERVICE[i]); 126 SERVICE[i] = toupper(SERVICE[i]);
129 } 127 }
130 128
@@ -275,19 +273,21 @@ main (int argc, char **argv)
275 printf("Quit string: %s\n", server_quit); 273 printf("Quit string: %s\n", server_quit);
276 } 274 }
277 printf("server_expect_count: %d\n", (int)server_expect_count); 275 printf("server_expect_count: %d\n", (int)server_expect_count);
278 for(i = 0; i < server_expect_count; i++) 276 for(size_t i = 0; i < server_expect_count; i++)
279 printf("\t%d: %s\n", i, server_expect[i]); 277 printf("\t%zd: %s\n", i, server_expect[i]);
280 } 278 }
281 279
282 /* if(len) later on, we know we have a non-NULL response */ 280 /* if(len) later on, we know we have a non-NULL response */
283 len = 0; 281 ssize_t len = 0;
282
284 if (server_expect_count) { 283 if (server_expect_count) {
284 ssize_t received = 0;
285 285
286 /* watch for the expect string */ 286 /* watch for the expect string */
287 while ((i = my_recv(buffer, sizeof(buffer))) > 0) { 287 while ((received = my_recv(buffer, sizeof(buffer))) > 0) {
288 status = realloc(status, len + i + 1); 288 status = realloc(status, len + received + 1);
289 memcpy(&status[len], buffer, i); 289 memcpy(&status[len], buffer, received);
290 len += i; 290 len += received;
291 status[len] = '\0'; 291 status[len] = '\0';
292 292
293 /* stop reading if user-forced */ 293 /* stop reading if user-forced */
@@ -307,6 +307,7 @@ main (int argc, char **argv)
307 if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0) 307 if(select(sd + 1, &rfds, NULL, NULL, &timeout) <= 0)
308 break; 308 break;
309 } 309 }
310
310 if (match == NP_MATCH_RETRY) 311 if (match == NP_MATCH_RETRY)
311 match = NP_MATCH_FAILURE; 312 match = NP_MATCH_FAILURE;
312 313
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index d1ded62..bb91c4a 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -402,7 +402,8 @@ get_ups_variable (const char *varname, char *buf)
402 402
403 /* create the command string to send to the UPS daemon */ 403 /* create the command string to send to the UPS daemon */
404 /* Add LOGOUT to avoid read failure logs */ 404 /* Add LOGOUT to avoid read failure logs */
405 if (snprintf (send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", ups_name, varname) >= sizeof(send_buffer)) { 405 int res = snprintf (send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", ups_name, varname);
406 if ( (res > 0) && ((size_t)res >= sizeof(send_buffer))) {
406 printf("%s\n", _("UPS name to long for buffer")); 407 printf("%s\n", _("UPS name to long for buffer"));
407 return ERROR; 408 return ERROR;
408 } 409 }
diff --git a/plugins/negate.c b/plugins/negate.c
index 79cca7e..745c12a 100644
--- a/plugins/negate.c
+++ b/plugins/negate.c
@@ -63,7 +63,6 @@ main (int argc, char **argv)
63 char *sub; 63 char *sub;
64 char **command_line; 64 char **command_line;
65 output chld_out, chld_err; 65 output chld_out, chld_err;
66 int i;
67 66
68 setlocale (LC_ALL, ""); 67 setlocale (LC_ALL, "");
69 bindtextdomain (PACKAGE, LOCALEDIR); 68 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -86,7 +85,7 @@ main (int argc, char **argv)
86 result = cmd_run_array (command_line, &chld_out, &chld_err, 0); 85 result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
87 } 86 }
88 if (chld_err.lines > 0) { 87 if (chld_err.lines > 0) {
89 for (i = 0; i < chld_err.lines; i++) { 88 for (size_t i = 0; i < chld_err.lines; i++) {
90 fprintf (stderr, "%s\n", chld_err.line[i]); 89 fprintf (stderr, "%s\n", chld_err.line[i]);
91 } 90 }
92 } 91 }
@@ -95,7 +94,7 @@ main (int argc, char **argv)
95 if (chld_out.lines == 0) 94 if (chld_out.lines == 0)
96 die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n")); 95 die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n"));
97 96
98 for (i = 0; i < chld_out.lines; i++) { 97 for (size_t i = 0; i < chld_out.lines; i++) {
99 if (subst_text && result >= 0 && result <= 4 && result != state[result]) { 98 if (subst_text && result >= 0 && result <= 4 && result != state[result]) {
100 /* Loop over each match found */ 99 /* Loop over each match found */
101 while ((sub = strstr (chld_out.line[i], state_text (result)))) { 100 while ((sub = strstr (chld_out.line[i], state_text (result)))) {
diff --git a/plugins/runcmd.c b/plugins/runcmd.c
index 4f3e349..32fd6b9 100644
--- a/plugins/runcmd.c
+++ b/plugins/runcmd.c
@@ -240,13 +240,12 @@ np_runcmd_close(int fd)
240void 240void
241runcmd_timeout_alarm_handler (int signo) 241runcmd_timeout_alarm_handler (int signo)
242{ 242{
243 size_t i;
244 243
245 if (signo == SIGALRM) 244 if (signo == SIGALRM)
246 puts(_("CRITICAL - Plugin timed out while executing system call")); 245 puts(_("CRITICAL - Plugin timed out while executing system call"));
247 246
248 long maxfd = mp_open_max(); 247 long maxfd = mp_open_max();
249 if(np_pids) for(i = 0; i < maxfd; i++) { 248 if(np_pids) for(long int i = 0; i < maxfd; i++) {
250 if(np_pids[i] != 0) kill(np_pids[i], SIGKILL); 249 if(np_pids[i] != 0) kill(np_pids[i], SIGKILL);
251 } 250 }
252 251
diff --git a/plugins/utils.c b/plugins/utils.c
index 7e14b6e..e871c5f 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -230,13 +230,21 @@ bool is_intnonneg (char *number) {
230 */ 230 */
231bool is_int64(char *number, int64_t *target) { 231bool is_int64(char *number, int64_t *target) {
232 errno = 0; 232 errno = 0;
233 uint64_t tmp = strtoll(number, NULL, 10); 233 char *endptr = { 0 };
234
235 int64_t tmp = strtoll(number, &endptr, 10);
234 if (errno != 0) { 236 if (errno != 0) {
235 return false; 237 return false;
236 } 238 }
239
240 if (*endptr == '\0') {
241 return 0;
242 }
243
237 if (tmp < INT64_MIN || tmp > INT64_MAX) { 244 if (tmp < INT64_MIN || tmp > INT64_MAX) {
238 return false; 245 return false;
239 } 246 }
247
240 if (target != NULL) { 248 if (target != NULL) {
241 *target = tmp; 249 *target = tmp;
242 } 250 }