diff --git a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c index 5bf4c65dcabd..dcc4361d2192 100644 --- a/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c +++ b/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c @@ -266,13 +266,13 @@ parse_octetstring(struct snmp_value *value, char *val) return (-1); } - value->v.octetstring.len = len; - - if((value->v.octetstring.octets = malloc(len)) == NULL) { + if ((value->v.octetstring.octets = malloc(len)) == NULL) { + value->v.octetstring.len = 0; syslog(LOG_ERR, "malloc failed: %s", strerror(errno)); return (-1); } + value->v.octetstring.len = len; memcpy(value->v.octetstring.octets, val, len); value->syntax = SNMP_SYNTAX_OCTETSTRING;