From d29c81fce08c2c6161a307deba4b9cf4675aeab0 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 7 Oct 2022 17:53:25 +0200 Subject: [PATCH] Fixed: [clixon_snmp module crashes on snmpwalk command](https://github.com/clicon/clixon/issues/378) --- CHANGELOG.md | 1 + apps/snmp/snmp_handler.c | 11 ++++++----- apps/snmp/snmp_lib.c | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9886f4f2..c88f4001 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ Developers may need to change their code ### Corrected Bugs +* Fixed: [clixon_snmp module crashes on snmpwalk command](https://github.com/clicon/clixon/issues/378) * Fixed: [unneeded trailing zero character on SNMP strings](https://github.com/clicon/clixon/issues/367) * Fixed: [message-id present on netconf app "hello"](https://github.com/clicon/clixon/issues/369) * Fixed: [SNMP "smiv2" yang extension doesn't work on augmented nodes](https://github.com/clicon/clixon/issues/366) diff --git a/apps/snmp/snmp_handler.c b/apps/snmp/snmp_handler.c index fa981e41..183e5515 100644 --- a/apps/snmp/snmp_handler.c +++ b/apps/snmp/snmp_handler.c @@ -146,13 +146,14 @@ snmp_scalar_return(cxobj *xs, char *reason = NULL; netsnmp_variable_list *requestvb = request->requestvb; int ret; + char *body = NULL; /* SMI default value, How is this different from yang defaults? */ if (yang_extension_value(ys, "defval", IETF_YANG_SMIV2_NS, NULL, &defaultval) < 0) goto done; - if (xs != NULL){ - if ((ret = type_xml2snmp_pre(xml_body(xs), ys, &xmlstr)) < 0) + if (xs != NULL && (body = xml_body(xs)) != NULL){ + if ((ret = type_xml2snmp_pre(body, ys, &xmlstr)) < 0) // XXX <--- goto done; if (ret == 0){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){ @@ -242,6 +243,7 @@ snmp_scalar_get(clicon_handle h, char *reason = NULL; netsnmp_variable_list *requestvb = request->requestvb; cxobj *xcache = NULL; + char *body = NULL; clicon_debug(1, "%s", __FUNCTION__); /* Prepare backend call by constructing namespace context */ @@ -270,9 +272,8 @@ snmp_scalar_get(clicon_handle h, * 1. From XML to SNMP string, there is a special case for enumeration, and for default value * 2. From SNMP string to SNMP binary value which invloves parsing */ - if (x != NULL){ - assert(xml_spec(x) == ys); - if ((ret = type_xml2snmp_pre(xml_body(x), ys, &xmlstr)) < 0) + if (x != NULL && (body = xml_body(x)) != NULL){ + if ((ret = type_xml2snmp_pre(body, ys, &xmlstr)) < 0) goto done; if (ret == 0){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){ diff --git a/apps/snmp/snmp_lib.c b/apps/snmp/snmp_lib.c index 21aa107c..5b979cd0 100644 --- a/apps/snmp/snmp_lib.c +++ b/apps/snmp/snmp_lib.c @@ -633,8 +633,8 @@ type_xml2snmp_pre(char *xmlstr0, char *str = NULL; int ret; - if (xmlstr1 == NULL){ - clicon_err(OE_UNIX, EINVAL, "xmlstr1"); + if (xmlstr0 == NULL || xmlstr1 == NULL){ + clicon_err(OE_UNIX, EINVAL, "xmlstr0/1 is NULL"); goto done; } /* Get yang type of leaf and trasnslate to ASN.1 */