Fixed: [clixon_snmp module crashes on snmpwalk command](https://github.com/clicon/clixon/issues/378)

This commit is contained in:
Olof hagsand 2022-10-07 17:53:25 +02:00
parent 11eccd5478
commit d29c81fce0
3 changed files with 9 additions and 7 deletions

View file

@ -75,6 +75,7 @@ Developers may need to change their code
### Corrected Bugs ### 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: [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: [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) * Fixed: [SNMP "smiv2" yang extension doesn't work on augmented nodes](https://github.com/clicon/clixon/issues/366)

View file

@ -146,13 +146,14 @@ snmp_scalar_return(cxobj *xs,
char *reason = NULL; char *reason = NULL;
netsnmp_variable_list *requestvb = request->requestvb; netsnmp_variable_list *requestvb = request->requestvb;
int ret; int ret;
char *body = NULL;
/* SMI default value, How is this different from yang defaults? /* SMI default value, How is this different from yang defaults?
*/ */
if (yang_extension_value(ys, "defval", IETF_YANG_SMIV2_NS, NULL, &defaultval) < 0) if (yang_extension_value(ys, "defval", IETF_YANG_SMIV2_NS, NULL, &defaultval) < 0)
goto done; goto done;
if (xs != NULL){ if (xs != NULL && (body = xml_body(xs)) != NULL){
if ((ret = type_xml2snmp_pre(xml_body(xs), ys, &xmlstr)) < 0) if ((ret = type_xml2snmp_pre(body, ys, &xmlstr)) < 0) // XXX <---
goto done; goto done;
if (ret == 0){ if (ret == 0){
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){ 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; char *reason = NULL;
netsnmp_variable_list *requestvb = request->requestvb; netsnmp_variable_list *requestvb = request->requestvb;
cxobj *xcache = NULL; cxobj *xcache = NULL;
char *body = NULL;
clicon_debug(1, "%s", __FUNCTION__); clicon_debug(1, "%s", __FUNCTION__);
/* Prepare backend call by constructing namespace context */ /* 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 * 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 * 2. From SNMP string to SNMP binary value which invloves parsing
*/ */
if (x != NULL){ if (x != NULL && (body = xml_body(x)) != NULL){
assert(xml_spec(x) == ys); if ((ret = type_xml2snmp_pre(body, ys, &xmlstr)) < 0)
if ((ret = type_xml2snmp_pre(xml_body(x), ys, &xmlstr)) < 0)
goto done; goto done;
if (ret == 0){ if (ret == 0){
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){ if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGVALUE)) != SNMPERR_SUCCESS){

View file

@ -633,8 +633,8 @@ type_xml2snmp_pre(char *xmlstr0,
char *str = NULL; char *str = NULL;
int ret; int ret;
if (xmlstr1 == NULL){ if (xmlstr0 == NULL || xmlstr1 == NULL){
clicon_err(OE_UNIX, EINVAL, "xmlstr1"); clicon_err(OE_UNIX, EINVAL, "xmlstr0/1 is NULL");
goto done; goto done;
} }
/* Get yang type of leaf and trasnslate to ASN.1 */ /* Get yang type of leaf and trasnslate to ASN.1 */