From 9008d31a26a8a5e8f27f0010eae48fb3299b9fad Mon Sep 17 00:00:00 2001 From: bstepankova Date: Mon, 19 Feb 2018 16:52:49 +0100 Subject: [PATCH 1/3] Problem: snmp-ups segfaults Solution: base_snmp_template_index() prevented from processing empty argument Signed-off-by: Barbora Stepankova --- drivers/snmp-ups.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/drivers/snmp-ups.c b/drivers/snmp-ups.c index 4b1efa5a15..13363f6945 100644 --- a/drivers/snmp-ups.c +++ b/drivers/snmp-ups.c @@ -561,18 +561,18 @@ void upsdrv_initups(void) dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stayoff"); } - /* Publish sysContact and sysLocation for all subdrivers */ - /* sysContact.0 */ - if (nut_snmp_get_str(".1.3.6.1.2.1.1.4.0", model, sizeof(model), NULL) == TRUE) - dstate_setinfo("device.contact", "%s", model); - else - upsdebugx(2, "Can't get and publish sysContact for device.contact"); - - /* sysLocation.0 */ - if (nut_snmp_get_str(".1.3.6.1.2.1.1.6.0", model, sizeof(model), NULL) == TRUE) - dstate_setinfo("device.location", "%s", model); - else - upsdebugx(2, "Can't get and publish sysLocation for device.location"); + /* Publish sysContact and sysLocation for all subdrivers */ + /* sysContact.0 */ + if (nut_snmp_get_str(".1.3.6.1.2.1.1.4.0", model, sizeof(model), NULL) == TRUE) + dstate_setinfo("device.contact", "%s", model); + else + upsdebugx(2, "Can't get and publish sysContact for device.contact"); + + /* sysLocation.0 */ + if (nut_snmp_get_str(".1.3.6.1.2.1.1.6.0", model, sizeof(model), NULL) == TRUE) + dstate_setinfo("device.location", "%s", model); + else + upsdebugx(2, "Can't get and publish sysLocation for device.location"); } void upsdrv_cleanup(void) @@ -1753,6 +1753,9 @@ void free_info(snmp_info_t *su_info_p) * the MIB, based on a test using a template OID */ int base_snmp_template_index(const snmp_info_t *su_info_p) { + if (!su_info_p) + return -1; + int base_index = -1; char test_OID[SU_INFOSIZE]; int template_type = get_template_type(su_info_p->info_type); @@ -2221,18 +2224,22 @@ bool_t daisychain_init() dstate_setinfo("device.model", "daisychain (1+%ld)", devices_count - 1); } } - } + + /* Finally, compute and store the base OID index and NUT offset */ + su_info_p = su_find_info("device.model"); + if (su_info_p != NULL) + { + device_template_index_base = base_snmp_template_index(su_info_p); + upsdebugx(1, "%s: device_template_index_base = %i", __func__, device_template_index_base); + device_template_offset = device_template_index_base - 1; + upsdebugx(1, "%s: device_template_offset = %i", __func__, device_template_offset); + } + } else { daisychain_enabled = FALSE; upsdebugx(1, "No device.count entry found, daisychain support not needed"); } - /* Finally, compute and store the base OID index and NUT offset */ - device_template_index_base = base_snmp_template_index(su_find_info("device.model")); - upsdebugx(1, "%s: device_template_index_base = %i", __func__, device_template_index_base); - device_template_offset = device_template_index_base - 1; - upsdebugx(1, "%s: device_template_offset = %i", __func__, device_template_offset); - return daisychain_enabled; } From 84c10a86f0cd2178993598d31a6042e074f0b559 Mon Sep 17 00:00:00 2001 From: bstepankova Date: Tue, 20 Feb 2018 09:17:38 +0100 Subject: [PATCH 2/3] Problem: index has to be counted for any device not just for daisychain Solution: counted for both Signed-off-by: Barbora Stepankova --- drivers/snmp-ups.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/snmp-ups.c b/drivers/snmp-ups.c index 13363f6945..48f05aea60 100644 --- a/drivers/snmp-ups.c +++ b/drivers/snmp-ups.c @@ -2225,21 +2225,23 @@ bool_t daisychain_init() } } - /* Finally, compute and store the base OID index and NUT offset */ - su_info_p = su_find_info("device.model"); - if (su_info_p != NULL) - { - device_template_index_base = base_snmp_template_index(su_info_p); - upsdebugx(1, "%s: device_template_index_base = %i", __func__, device_template_index_base); - device_template_offset = device_template_index_base - 1; - upsdebugx(1, "%s: device_template_offset = %i", __func__, device_template_offset); - } } else { daisychain_enabled = FALSE; upsdebugx(1, "No device.count entry found, daisychain support not needed"); } + /* Finally, compute and store the base OID index and NUT offset */ + su_info_p = su_find_info("device.model"); + if (su_info_p != NULL) { + device_template_index_base = base_snmp_template_index(su_info_p); + upsdebugx(1, "%s: device_template_index_base = %i", __func__, device_template_index_base); + device_template_offset = device_template_index_base - 1; + upsdebugx(1, "%s: device_template_offset = %i", __func__, device_template_offset); + } + + + return daisychain_enabled; } From 09b286e52d8d61665891e35ed723f8419d571af6 Mon Sep 17 00:00:00 2001 From: bstepankova Date: Tue, 20 Feb 2018 13:49:56 +0100 Subject: [PATCH 3/3] Problem: debug info needs improvement Solution: added Signed-off-by: Barbora Stepankova --- drivers/snmp-ups.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/snmp-ups.c b/drivers/snmp-ups.c index 48f05aea60..89986e2cd6 100644 --- a/drivers/snmp-ups.c +++ b/drivers/snmp-ups.c @@ -2224,7 +2224,6 @@ bool_t daisychain_init() dstate_setinfo("device.model", "daisychain (1+%ld)", devices_count - 1); } } - } else { daisychain_enabled = FALSE; @@ -2239,8 +2238,9 @@ bool_t daisychain_init() device_template_offset = device_template_index_base - 1; upsdebugx(1, "%s: device_template_offset = %i", __func__, device_template_offset); } - - + else { + upsdebugx(1, "%s: No device.model entry found.", __func__); + } return daisychain_enabled; }