Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Jan 2017 08:55:41 +0000 (UTC)
From:      Ngie Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r312048 - stable/11/contrib/bsnmp/lib
Message-ID:  <201701130855.v0D8tfYI059413@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Fri Jan 13 08:55:41 2017
New Revision: 312048
URL: https://svnweb.freebsd.org/changeset/base/312048

Log:
  MFC r310729:
  
  Prevent improper memory accesses after calling snmp_pdu_free and snmp_value_free
  
  snmp_pdu_free: set pdu->nbindings to 0 to limit the damage that
  could happen if a pdu was reused after calling the function, and
  as both stack and heap allocation types are used in contrib/bsnmp
  and usr.sbin/bsnmpd.
  
  snmp_value_free: NULL out value->v.octetstring.octets after calling
  free on it to prevent a double-free from occurring.

Modified:
  stable/11/contrib/bsnmp/lib/snmp.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/contrib/bsnmp/lib/snmp.c
==============================================================================
--- stable/11/contrib/bsnmp/lib/snmp.c	Fri Jan 13 08:55:37 2017	(r312047)
+++ stable/11/contrib/bsnmp/lib/snmp.c	Fri Jan 13 08:55:41 2017	(r312048)
@@ -1154,8 +1154,11 @@ snmp_pdu_dump(const struct snmp_pdu *pdu
 void
 snmp_value_free(struct snmp_value *value)
 {
-	if (value->syntax == SNMP_SYNTAX_OCTETSTRING)
+
+	if (value->syntax == SNMP_SYNTAX_OCTETSTRING) {
 		free(value->v.octetstring.octets);
+		value->v.octetstring.octets = NULL;
+	}
 	value->syntax = SNMP_SYNTAX_NULL;
 }
 
@@ -1216,6 +1219,7 @@ snmp_pdu_free(struct snmp_pdu *pdu)
 
 	for (i = 0; i < pdu->nbindings; i++)
 		snmp_value_free(&pdu->bindings[i]);
+	pdu->nbindings = 0;
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701130855.v0D8tfYI059413>