Similar to r310954, set .len to 0 on malloc failure and to len
only
on success MFC after: 1 week
This commit is contained in:
parent
39ebb4e1e0
commit
560c5ef9a2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=310960
@ -114,9 +114,11 @@ string_get(struct snmp_value *value, const u_char *ptr, ssize_t len)
|
||||
}
|
||||
if (len == -1)
|
||||
len = strlen(ptr);
|
||||
value->v.octetstring.len = (u_long)len;
|
||||
if ((value->v.octetstring.octets = malloc((size_t)len)) == NULL)
|
||||
if ((value->v.octetstring.octets = malloc((size_t)len)) == NULL) {
|
||||
value->v.octetstring.len = 0;
|
||||
return (SNMP_ERR_RES_UNAVAIL);
|
||||
}
|
||||
value->v.octetstring.len = (u_long)len;
|
||||
memcpy(value->v.octetstring.octets, ptr, (size_t)len);
|
||||
return (SNMP_ERR_NOERROR);
|
||||
}
|
||||
@ -138,9 +140,11 @@ string_get_max(struct snmp_value *value, const u_char *ptr, ssize_t len,
|
||||
len = strlen(ptr);
|
||||
if ((size_t)len > maxlen)
|
||||
len = maxlen;
|
||||
value->v.octetstring.len = (u_long)len;
|
||||
if ((value->v.octetstring.octets = malloc((size_t)len)) == NULL)
|
||||
if ((value->v.octetstring.octets = malloc((size_t)len)) == NULL) {
|
||||
value->v.octetstring.len = 0;
|
||||
return (SNMP_ERR_RES_UNAVAIL);
|
||||
}
|
||||
value->v.octetstring.len = (u_long)len;
|
||||
memcpy(value->v.octetstring.octets, ptr, (size_t)len);
|
||||
return (SNMP_ERR_NOERROR);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user