Date: Sat, 31 Dec 2016 12:37:53 +0000 (UTC) From: Ngie Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310960 - head/contrib/bsnmp/snmpd Message-ID: <201612311237.uBVCbrd6080041@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Sat Dec 31 12:37:53 2016 New Revision: 310960 URL: https://svnweb.freebsd.org/changeset/base/310960 Log: Similar to r310954, set .len to 0 on malloc failure and to `len` only on success MFC after: 1 week Modified: head/contrib/bsnmp/snmpd/export.c Modified: head/contrib/bsnmp/snmpd/export.c ============================================================================== --- head/contrib/bsnmp/snmpd/export.c Sat Dec 31 12:32:50 2016 (r310959) +++ head/contrib/bsnmp/snmpd/export.c Sat Dec 31 12:37:53 2016 (r310960) @@ -114,9 +114,11 @@ string_get(struct snmp_value *value, con } 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, 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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201612311237.uBVCbrd6080041>