From cda77b48104a4006da16068e4986f2b1d100ac82 Mon Sep 17 00:00:00 2001 From: Mikhail Grigorev Date: Thu, 14 Sep 2023 22:15:47 +0300 Subject: [PATCH] [ZBX-22234] fixed incorrect SNMPINDEX offset retrieval in SNMP discovery (dgoloscapov) --- ChangeLog | 1 + PATCHLIST.md | 1 + src/zabbix_server/poller/checks_snmp.c | 22 ++++++++++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b1511a46..895bd02d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -65,6 +65,7 @@ A......... [ZBX-21332] fixed runtime errors when linking items from two template .......PS. [ZBX-22026] fixed SNMP agent item going to unsupported state on NULL result (vso) .......PS. [ZBX-22032] added cookie engine to HTTP check (askolmeisters) ........S. [ZBX-22215] fixed incorrectly quoted function parameter parsing (wiper) +........S. [ZBX-22234] fixed incorrect SNMPINDEX offset retrieval in SNMP discovery (dgoloscapov) .......PS. [ZBX-22304] fixed duplication in web scenario error message, when curl could not resolve host (mprihodko) ...G...... [ZBX-22452] fixed Windows Zabbix agent web.page.* unsupported item keys (akozlovs) ...G...... [ZBX-22470] fixed hang on logging when establishing an encrypted connection in Zabbix agent 2 (kprutkovs) diff --git a/PATCHLIST.md b/PATCHLIST.md index e512ab48..5b13a0f9 100644 --- a/PATCHLIST.md +++ b/PATCHLIST.md @@ -299,6 +299,7 @@ [ZBX-22026] fixed SNMP agent item going to unsupported state on NULL result (https://support.zabbix.com/browse/ZBX-22026) [ZBX-22032] added cookie engine to HTTP check (https://support.zabbix.com/browse/ZBX-22032) [ZBX-22215] fixed incorrectly quoted function parameter parsing (https://support.zabbix.com/browse/ZBX-22215) +[ZBX-22234] fixed incorrect SNMPINDEX offset retrieval in SNMP discovery (https://support.zabbix.com/browse/ZBX-22234) [ZBX-22304] fixed duplication in web scenario error message, when curl could not resolve host (https://support.zabbix.com/browse/ZBX-22304) [ZBX-22452] fixed Windows Zabbix agent web.page.* unsupported item keys (https://support.zabbix.com/browse/ZBX-22452) [ZBX-22470] fixed hang on logging when establishing an encrypted connection in Zabbix agent 2 (https://support.zabbix.com/browse/ZBX-22470) diff --git a/src/zabbix_server/poller/checks_snmp.c b/src/zabbix_server/poller/checks_snmp.c index 2f64f28f..e4eb24b4 100644 --- a/src/zabbix_server/poller/checks_snmp.c +++ b/src/zabbix_server/poller/checks_snmp.c @@ -797,7 +797,7 @@ static int zbx_snmp_print_oid(char *buffer, size_t buffer_len, const oid *objid, } static int zbx_snmp_choose_index(char *buffer, size_t buffer_len, const oid *objid, size_t objid_len, - size_t root_string_len, size_t root_numeric_len) + size_t root_string_len, size_t root_numeric_len, char *root_oid) { oid parsed_oid[MAX_OID_LEN]; size_t parsed_oid_len = MAX_OID_LEN; @@ -868,7 +868,19 @@ static int zbx_snmp_choose_index(char *buffer, size_t buffer_len, const oid *obj if (NULL == strchr(printed_oid, '"') && NULL == strchr(printed_oid, '\'')) { - zbx_strlcpy(buffer, printed_oid + root_string_len + 1, buffer_len); + if (0 != strncmp(printed_oid, root_oid, strlen(root_oid))) + { + size_t offset = 0; + char *sep; + + if (NULL != (sep = strstr(printed_oid, "::"))) + offset = sep - printed_oid + 2; + + zbx_strlcpy(buffer, printed_oid + offset, buffer_len); + } + else + zbx_strlcpy(buffer, printed_oid + root_string_len + 1, buffer_len); + return SUCCEED; } @@ -1009,7 +1021,7 @@ static int zbx_snmp_walk(struct snmp_session *ss, const DC_ITEM *item, const cha struct snmp_pdu *pdu, *response; oid anOID[MAX_OID_LEN], rootOID[MAX_OID_LEN]; size_t anOID_len = MAX_OID_LEN, rootOID_len = MAX_OID_LEN, root_string_len, root_numeric_len; - char oid_index[MAX_STRING_LEN]; + char oid_index[MAX_STRING_LEN], root_oid[MAX_STRING_LEN]; struct variable_list *var; int status, level, running, num_vars, check_oid_increase = 1, ret = SUCCEED; AGENT_RESULT snmp_result; @@ -1038,6 +1050,8 @@ static int zbx_snmp_walk(struct snmp_session *ss, const DC_ITEM *item, const cha root_string_len = strlen(oid_index); + zbx_strlcpy(root_oid, oid_index, sizeof(root_oid)); + if (-1 == zbx_snmp_print_oid(oid_index, sizeof(oid_index), rootOID, rootOID_len, ZBX_OID_INDEX_NUMERIC)) { zbx_snprintf(error, max_error_len, "zbx_snmp_print_oid(): cannot print OID \"%s\"" @@ -1174,7 +1188,7 @@ static int zbx_snmp_walk(struct snmp_session *ss, const DC_ITEM *item, const cha } if (SUCCEED != zbx_snmp_choose_index(oid_index, sizeof(oid_index), var->name, - var->name_length, root_string_len, root_numeric_len)) + var->name_length, root_string_len, root_numeric_len, root_oid)) { zbx_snprintf(error, max_error_len, "zbx_snmp_choose_index():" " cannot choose appropriate index while walking for"