[Nagiosplug-devel] [ nagiosplug-Bugs-866485 ] Overflow in check_swap

SourceForge.net noreply at sourceforge.net
Wed Feb 25 00:23:00 CET 2004


Bugs item #866485, was opened at 2003-12-27 18:56
Message generated for change (Comment added) made by kdebisschop
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=397597&aid=866485&group_id=29880

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Johannes Formann (jformann)
Assigned to: Nobody/Anonymous (nobody)
Summary: Overflow in check_swap

Initial Comment:
When running check_swap on server with more than 4 GB 
swap (in this case with about 16 GB) it will report a false 
percentage as beeing used:

/opt/master/nagios/libexec/check_swap -w 30% -c 70%
WARNING - Swap used: 32% (1412804608 out of 
4294967295)

# free
             total       used       free     shared    buffers     
cached
Mem:       4011044    4001688       9356          0      23168    
3668088
-/+ buffers/cache:     310432    3700612
Swap:     16097500    1379860   14717640


I've checked this from 1.3 over 1.3.1 up to 1.4a1


I think the vars must be changed from long to long long.

----------------------------------------------------------------------

>Comment By: Karl DeBisschop (kdebisschop)
Date: 2004-02-25 03:18

Message:
Logged In: YES 
user_id=1671

I think changing the vars to long long as you suggest is a
better option than the patch below. The change has been made
and committed to CVS head. I had a test case which showed
incorrect info before the patch and correct info after, so
in at least one case the patch works as expected.

----------------------------------------------------------------------

Comment By: Johannes Formann (jformann)
Date: 2004-01-01 14:40

Message:
Logged In: YES 
user_id=938859

Someone was so nice, to take a look (thanks Hunz) and made me 
a smal patch I'd like to share

*** ../nagios-plugins-1.4.0alpha1/plugins/check_swap.c  Wed Nov 
12 05:37:19 2003
--- plugins/check_swap.c        Thu Jan  1 19:28:34 2004
***************
*** 82,87 ****
--- 82,95 ----
  #ifdef HAVE_PROC_MEMINFO
          fp = fopen (PROC_MEMINFO, "r");
          while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
+                 unsigned long tmp;
+                 if(sscanf(input_buffer, "%s %lu", str, &tmp)==2) {
+                         if(!
strncmp(str,"SwapTotal",strlen("SwapTotal")))
+                                 total_swap+=(tmp>>10);
+                         else if(!
strncmp(str,"SwapFree",strlen("SwapFree")))
+                                 free_swap+=(tmp>>10);
+                 }
+                 /*
                  if (sscanf (input_buffer, " %s %lu %lu %lu", str, 
&dsktotal, &dskused, &dskfree) == 4 &&
                      strstr (str, "Swap")) {
                          dsktotal = dsktotal / 1048576;
***************
*** 97,104 ****
--- 105,114 ----
                                          asprintf (&status, "%s [%lu 
(%d%%)]", status, dskfree, 100 - percent);
                          }
                  }
+                 */
          }
          fclose(fp);
+         used_swap=total_swap-free_swap;
  #else
  # ifdef HAVE_SWAP
          asprintf(&swap_command, "%s", SWAP_COMMAND);
***************
*** 240,246 ****
  check_swap (int usp, long unsigned int free_swap)
  {
        int result = STATE_UNKNOWN;
-       free_swap = free_swap * 1024;           /* Convert back to 
bytes as warn and crit specified in bytes */
        if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - 
crit_percent))
                result = STATE_CRITICAL;
        else if (crit_size > 0 && free_swap <= crit_size)
--- 251,256 ----
***************
*** 399,411 ****
  
        printf (_("\n   -w, --warning=INTEGER\n!    Exit with WARNING status if less than INTEGER bytes of swap 
space are free\n   -w, --warning=PERCENT%%\n!    Exit with WARNING status if less than PERCENT of swap space 
has been used\n   -c, --critical=INTEGER\n!    Exit with CRITICAL status if less than INTEGER bytes of swap 
space are free\n   -c, --critical=PERCENT%%\n!    Exit with CRITCAL status if less than PERCENT of swap space 
has been used\n   -a, --allswaps\n      Conduct comparisons for all swap partitions, one by one\n"));
  
--- 410,422 ----
  
          printf (_("\n   -w, --warning=INTEGER\n!    Exit with WARNING status if less than INTEGER mega bytes of 
swap space are free\n   -w, --warning=PERCENT%%\n!    Exit with WARNING status if less than PERCENT of swap space 
are free\n   -c, --critical=INTEGER\n!    Exit with CRITICAL status if less than INTEGER mega bytes of 
swap space are free\n   -c, --critical=PERCENT%%\n!    Exit with CRITCAL status if less than PERCENT of swap space 
are free\n   -a, --allswaps\n      Conduct comparisons for all swap partitions, one by one\n"));
  
***************
*** 426,433 ****
  print_usage (void)
  {
        printf (_("Usage:\n!  %s [-a] -w <used_percentage>%% -c 
<used_percentage>%%\n!  %s [-a] -w <bytes_free> -c <bytes_free>\n   %s (-h | --help) for detailed help\n   %s (-V | --version) for version information\n"),
                progname, progname, progname, progname);
--- 437,444 ----
  print_usage (void)
  {
          printf (_("Usage:\n!  %s [-a] -w <free_percentage>%% -c 
<free_percentage>%%\n!  %s [-a] -w <mega_bytes_free> -c <mega_bytes_free>\n   %s (-h | --help) for detailed help\n   %s (-V | --version) for version information\n"),
                  progname, progname, progname, progname);


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=397597&aid=866485&group_id=29880




More information about the Devel mailing list