Set value->v.octetstring.len to a correct value on malloc success/failure

The previous code always set value->v.octetstring.len to len, regardless
of the result from the malloc call. This misleads the caller on malloc
failure. Set .len to len on success and 0 on failure.

MFC after:	1 week
Reported by:	Coverity
CID:		1007590
This commit is contained in:
Enji Cooper 2016-12-31 12:14:25 +00:00
parent a0e0e1ffa5
commit c4114bd1f5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=310954

View File

@ -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;