Code

ipmi plugin: Fix an off-by-one error.
authorPeter Holik <holik@it-technology.at>
Thu, 19 Feb 2009 12:00:59 +0000 (13:00 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Thu, 19 Feb 2009 12:00:59 +0000 (13:00 +0100)
Hi,

One of my ipmi sensors has a name longer than DATA_MAX_NAME_LEN and this
results in a SEGV.

cu Peter

src/ipmi.c

index f3ba95a885a152d73ecc3d9c9162e87410c1e2fc..f026c171680d25f285701e2f11ab5c256bb9d446 100644 (file)
@@ -225,7 +225,7 @@ static int sensor_list_add (ipmi_sensor_t *sensor)
   ipmi_sensor_get_name (sensor, sensor_name, sizeof (sensor_name));
   sensor_name[sizeof (sensor_name) - 1] = 0;
 
-  len = DATA_MAX_NAME_LEN - strlen(sensor_name);
+  len = DATA_MAX_NAME_LEN - strlen(sensor_name) - 1;
   strncat(sensor_name, " ", len--);
   strncat(sensor_name, ipmi_entity_get_entity_id_string(ent), len);
 
@@ -237,7 +237,7 @@ static int sensor_list_add (ipmi_sensor_t *sensor)
     char *sensor_name_ptr_id = strstr (sensor_name, "(");
 
     sensor_name_ptr += 2;
-    len = DATA_MAX_NAME_LEN - strlen(sensor_name);
+    len = DATA_MAX_NAME_LEN - strlen(sensor_name) - 1;
     strncat(sensor_name, " ", len--);
     strncat(sensor_name, sensor_name_ptr_id, 
       MIN(sensor_name_ptr - sensor_name_ptr_id - 1, len));