[Nagiosplug-devel] [ nagiosplug-Patches-2696823 ] check_mysql.c: Negative value in array

SourceForge.net noreply at sourceforge.net
Mon Mar 23 13:09:36 CET 2009


Patches item #2696823, was opened at 2009-03-20 04:21
Message generated for change (Comment added) made by dermoth
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=397599&aid=2696823&group_id=29880

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Bugfix
>Group: release-1.4.14
Status: Open
>Resolution: Accepted
Priority: 5
Private: No
Submitted By: Oskar Ahner (oskara67)
>Assigned to: Thomas Guyot-Sionnest (dermoth)
Summary: check_mysql.c: Negative value in array

Initial Comment:
Version: nagios-plugins-1.4.13, file check_mysql.c, version  '2034.

Cause: For mysql-server verson 4.0.29 the column 'Seconds_Behind_Master' does not exist. This causes a segmentation fault when executing.

Description: 

In main() the int 'seconds_behind_field' has the value -1 when accessed in the following statement:

 if ((seconds_behind_field != -1) && (strcmp (row[seconds_behind_field], "NULL") != 0)) {
				double value = atof(row[seconds_behind_field]);

Here is a simple patch:

--- nagios-plugins-1.4.13/plugins/check_mysql.c	2008-08-16 06:47:32.000000000 +0200
+++ nagios-plugins-1.4.13.oskar/plugins/check_mysql.c	2009-03-19 16:50:18.000000000 +0100
@@ -181,13 +181,14 @@
 					continue;
 				}
 			}
+
 			if ((slave_io_field < 0) || (slave_sql_field < 0) || (num_fields == 0)) {
 				mysql_free_result (res);
 				mysql_close (&mysql);
 				die (STATE_CRITICAL, "Slave status unavailable\n");
 			}
 			
-			snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], row[seconds_behind_field]);
+			snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown");
 			if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) {
 				mysql_free_result (res);
 				mysql_close (&mysql);


Regards,

Oskar


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

>Comment By: Thomas Guyot-Sionnest (dermoth)
Date: 2009-03-23 08:09

Message:
Thanks!

Since I don't have old slaves to test with, I tested by commenting out the
code block that look for said line.

I will commit it tonight or tomorrow.

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

Comment By: Oskar Ahner (oskara67)
Date: 2009-03-20 04:25

Message:
Sorry, I wrote wrong line, it core dumps when this line is executed,
because 'seconds_behind_value" is -1.
The patch is correct however.


snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s
Seconds Behind Master: %s", r
ow[slave_io_field], row[slave_sql_field], row[seconds_behind_field]);


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

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




More information about the Devel mailing list