summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-10-19 12:10:55 +0200
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2023-10-19 12:10:55 +0200
commit07f9c438f31de7a280e43c4196a32d200ad41fbe (patch)
tree642bd4478a70665df23b83cb7b48770c3020c570 /plugins
parent47cb10013e6935bb6cdf470925ea5a5f74464646 (diff)
downloadmonitoring-plugins-07f9c438f31de7a280e43c4196a32d200ad41fbe.tar.gz
Fixes for -Wsign-compare
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_apt.c17
-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_procs.c4
-rw-r--r--plugins/check_snmp.c31
-rw-r--r--plugins/check_tcp.c14
-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
11 files changed, 66 insertions, 55 deletions
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index fa982ae3..290c88ed 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 }
@@ -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 1f5f72d4..2a23b397 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 153e492f..9c0dc349 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 82dc264a..5e20214c 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_procs.c b/plugins/check_procs.c
index 1637e3e3..6e3feaec 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 405ede3a..01bee231 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,7 +254,9 @@ 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 */
@@ -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
@@ -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 a1a14b45..c103612a 100644
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
@@ -102,7 +102,6 @@ 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;
@@ -124,7 +123,7 @@ main (int argc, char **argv)
124 len = strlen(progname); 123 len = strlen(progname);
125 if(len > 6 && !memcmp(progname, "check_", 6)) { 124 if(len > 6 && !memcmp(progname, "check_", 6)) {
126 SERVICE = strdup(progname + 6); 125 SERVICE = strdup(progname + 6);
127 for(i = 0; i < len - 6; i++) 126 for(size_t i = 0; i < len - 6; i++)
128 SERVICE[i] = toupper(SERVICE[i]); 127 SERVICE[i] = toupper(SERVICE[i]);
129 } 128 }
130 129
@@ -275,7 +274,7 @@ main (int argc, char **argv)
275 printf("Quit string: %s\n", server_quit); 274 printf("Quit string: %s\n", server_quit);
276 } 275 }
277 printf("server_expect_count: %d\n", (int)server_expect_count); 276 printf("server_expect_count: %d\n", (int)server_expect_count);
278 for(i = 0; i < server_expect_count; i++) 277 for(size_t i = 0; i < server_expect_count; i++)
279 printf("\t%d: %s\n", i, server_expect[i]); 278 printf("\t%d: %s\n", i, server_expect[i]);
280 } 279 }
281 280
@@ -284,10 +283,11 @@ main (int argc, char **argv)
284 if (server_expect_count) { 283 if (server_expect_count) {
285 284
286 /* watch for the expect string */ 285 /* watch for the expect string */
287 while ((i = my_recv(buffer, sizeof(buffer))) > 0) { 286 size_t received = 0;
288 status = realloc(status, len + i + 1); 287 while ((received = my_recv(buffer, sizeof(buffer))) > 0) {
289 memcpy(&status[len], buffer, i); 288 status = realloc(status, len + received + 1);
290 len += i; 289 memcpy(&status[len], buffer, received);
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 */
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index d1ded620..bb91c4ad 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 79cca7e0..745c12ac 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 4f3e349b..32fd6b96 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 7e14b6e4..e871c5f7 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 }