File monitoring-plugins-snmp-0.6.0-segfault-performance.patch of Package monitoring-plugins-snmp-C

diff -u -r monitoring-plugins-snmp/src/check_snmp_int.c monitoring-plugins-snmp/src/check_snmp_int.c
--- monitoring-plugins-snmp/src/check_snmp_int.c	2011-09-20 15:50:59.769011789 +0200
+++ monitoring-plugins-snmp/src/check_snmp_int.c	2011-09-21 03:49:10.349011992 +0200
@@ -1,6 +1,6 @@
 #include "nagios_common_snmp.h"
 
-#define SCRIPT_VERSION 0.5
+#define SCRIPT_VERSION 0.6
 #define TMP_FILE_NAME_PREFIX "tmp_Nagios_int."
 /* default delta for averages : 300s = 5min */
 #define DEFAULT_DELTA_AVERAGE 300
@@ -581,61 +581,67 @@
 			found_data=0; /* set to 1 if correct data is found (between trigger_low and trigger) */
 			if (file_ret ==0) {
 				j=rows-1;
-				do {
-					if ((file_values[j][0] < trigger) && (file_values[j][0] > trigger_low)) {
-
-						/* Define the speed metric ( K | M | G ) (Bits|Bytes) or % */
-						if (o_prct==1) {  /* in % of speed */
-							/* Speed is in bits/s, calculated speed is in Bytes/s */
-							speed_metric=interface_speed/800;
-							strcpy(speed_unit,"%");
+				/* Define the speed metric ( K | M | G ) (Bits|Bytes) or % */
+				if (o_prct==1) {  /* in % of speed */
+					/* Speed is in bits/s, calculated speed is in Bytes/s */
+					speed_metric=interface_speed/800;
+					strcpy(speed_unit,"%");
+				} else {
+					if (o_kbits==1) { /*  metric in bits */
+						if (o_meg==1) { /*  in Mbit/s = 1000000 bit/s */
+							  speed_metric=125000; /*   (1000/8) * 1000 */
+							  strcpy(speed_unit,"Mbps");
+						} else {
+							if (o_gig==1) { /*  in Gbit/s = 1000000000 bit/s */
+								  speed_metric=125000000; /*   (1000/8) * 1000 * 1000 */
+								  strcpy(speed_unit,"Gbps");
+							} else { /*  in Kbits */
+								  speed_metric=125; /*   ( 1000/8 ) */
+								  strcpy(speed_unit,"Kbps");
+							}
+						}
+					} else { /*  metric in byte */
+						if (o_meg==1) { /*  in Mbits */
+							  speed_metric=1048576; /*  1024^2 */
+							  strcpy(speed_unit,"MBps");
 						} else {
-							if (o_kbits==1) { /*  metric in bits */
-								if (o_meg==1) { /*  in Mbit/s = 1000000 bit/s */
-									  speed_metric=125000; /*   (1000/8) * 1000 */
-									  strcpy(speed_unit,"Mbps");
-							    } else {
-									if (o_gig==1) { /*  in Gbit/s = 1000000000 bit/s */
-										  speed_metric=125000000; /*   (1000/8) * 1000 * 1000 */
-										  strcpy(speed_unit,"Gbps");
-									} else { /*  in Kbits */
-										  speed_metric=125; /*   ( 1000/8 ) */
-										  strcpy(speed_unit,"Kbps");
-									}
-								}
-							} else { /*  metric in byte */
-							    if (o_meg==1) { /*  in Mbits */
-									  speed_metric=1048576; /*  1024^2 */
-									  strcpy(speed_unit,"MBps");
-							    } else {
-									if (o_gig==1) { /*  in Mbits */
-										  speed_metric=1073741824; /*  1024^3 */
-										  strcpy(speed_unit,"GBps");
-									} else {
-										  speed_metric=1024; /*  1024^3 */
-										  strcpy(speed_unit,"KBps");
-									}
-								}
+							if (o_gig==1) { /*  in Mbits */
+								  speed_metric=1073741824; /*  1024^3 */
+								  strcpy(speed_unit,"GBps");
+							} else {
+								  speed_metric=1024; /*  1024^3 */
+								  strcpy(speed_unit,"KBps");
 							}
 						}
+					}
+				}
+				do {
+					if ((file_values[j][0] < trigger) && (file_values[j][0] > trigger_low)) {						
 						/*  check if the counter is back to 0 after 2^32 (highperf is using another OID ) */
 						/*  Check counter (s) */
 						if (o_highperf==0) {
-							overfl = (int_state[i].in_oct >= file_values[j][1] ) ? 0 : 4294967296ULL;
-						} else { /* test if reset of counter has occured with highperf counters : TODO*/
-							overfl = 0;
+							overfl = 4294967295ULL;
+						} else {
+							overfl = 18446744073709551615ULL;
 						}
-						checkperf_out_raw[0] = ( (overfl + int_state[i].in_oct - file_values[j][1])/
+						if (int_state[i].in_oct >= file_values[j][1]) {
+							checkperf_out_raw[0] = ( (int_state[i].in_oct - file_values[j][1])/
+			      			      (timenow - file_values[j][0] ));						
+						} else {
+							// Overflow
+							checkperf_out_raw[0] = ( (overfl - file_values[j][1] + int_state[i].in_oct)/
 			      			      (timenow - file_values[j][0] ));
+						}
 						checkperf_out[0] = checkperf_out_raw[0] / speed_metric;
 						
-						if (o_highperf==0) {
-							overfl = (int_state[i].in_oct >= file_values[j][1] ) ? 0 : 4294967296ULL;
-						} else { /* test if reset of counter has occured with highperf counters : TODO*/
-							overfl = 0;
+						if (int_state[i].out_oct >= file_values[j][2]) {
+							checkperf_out_raw[1] = ( (int_state[i].out_oct - file_values[j][2])/
+			      			      (timenow - file_values[j][0] ));						
+						} else {
+							// Overflow
+							checkperf_out_raw[1] = ( (overfl - file_values[j][2] + int_state[i].in_oct)/
+			      			      (timenow - file_values[j][0] ));
 						}
-						checkperf_out_raw[1] = ( (overfl + int_state[i].out_oct - file_values[j][2])/
-						      (timenow - file_values[j][0] ));
 						checkperf_out[1] = checkperf_out_raw[1] / speed_metric;
 			    
 					    if (o_ext_checkperf==1) {
@@ -680,7 +686,7 @@
 				/*  check 2 or 6 values depending on ext_check_perf */
 				num_checkperf=(o_ext_checkperf==1)?6:2;
 				for (j=0;j < num_checkperf;j++) {
-					if (o_verb) printf(_("Interface %i, check %i : %f\n"),i,j,checkperf_out[j]);
+					if (o_verb) printf(_("Interface %i, check %i : is:%f warn:%f crit:%f\n"),i,j,checkperf_out[j],o_warn[j],o_crit[j]);
 					if (j!=0) strcat_output("/");
 					sprintf(buffer,"%.1f",checkperf_out[j]); /* put  value in string buffer */
 					if ((o_crit[j]!=0) && (checkperf_out[j]>o_crit[j])) { 
@@ -717,7 +723,7 @@
 			if (o_perfp==1) { /* output in % of speed */
 				if (found_data==1) {
 					p_output_float(interface_index[i]->value,
-					checkperf_out_raw[0] * 800 / interface_speed,
+						checkperf_out_raw[0] * 800 / interface_speed,
 						"%.0f","_in_prct","%",
 						(o_warn[0]!=0)?1:0,o_warn[0],
 						(o_crit[0]!=0)?1:0,o_crit[0],
diff -u -r monitoring-plugins-snmp/src/nagios_common_snmp.c monitoring-plugins-snmp/src/nagios_common_snmp.c
--- monitoring-plugins-snmp/src/nagios_common_snmp.c	2011-09-20 15:50:59.769011789 +0200
+++ monitoring-plugins-snmp/src/nagios_common_snmp.c	2011-09-21 05:43:31.777011848 +0200
@@ -735,9 +735,9 @@
 	int i,j,start;
 	
 	if ((FICHIER=fopen(file_name,"w")) == NULL) return 1;
-	if (rows > max_rows ) start = rows - max_rows ; 
+	if (rows >= max_rows ) start = rows - max_rows + 1; 
 	else start = 0;
-	for (i=0;i<rows;i++) {
+	for (i=start;i<rows;i++) {
 		for (j=0;j<items-1;j++) fprintf(FICHIER,"%llu:",values[i][j]);		
 		fprintf(FICHIER,"%llu\n",values[i][items-1]);
 	}
@@ -765,7 +765,8 @@
 		  if ((*pos2==0)&&(i!=(items-1))) return 1;
 		  memcpy(buffer2,pos,pos2-pos);
 		  buffer2[pos2-pos]=0;
-		  values[*rows][i]=strtoll(buffer2,&endptr,10); /* TODO test ==LLONG_MIN) return 1; */
+		  if (*rows < MAX_ROWS) /* Silently ignore to much lines */
+			  values[*rows][i]=strtoll(buffer2,&endptr,10); /* TODO test ==LLONG_MIN) return 1; */
 		  pos=pos2+1;		  
 		}
 		(*rows)++;