From 8373993535327bc2e7250e98a1cd50fade281490 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Fri, 30 Dec 2016 23:44:39 +0000 Subject: [PATCH] Guard against use-after-free after calling mibif_free(..) Set variables to NULL after calling free. Also, remove unnecessary if (x != NULL) checks before calling free(x) MFC after: 1 week --- contrib/bsnmp/snmp_mibII/mibII.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/contrib/bsnmp/snmp_mibII/mibII.c b/contrib/bsnmp/snmp_mibII/mibII.c index 3719e0074afe..a1053988b8c6 100644 --- a/contrib/bsnmp/snmp_mibII/mibII.c +++ b/contrib/bsnmp/snmp_mibII/mibII.c @@ -707,10 +707,11 @@ mibif_free(struct mibif *ifp) } free(ifp->private); - if (ifp->physaddr != NULL) - free(ifp->physaddr); - if (ifp->specmib != NULL) - free(ifp->specmib); + ifp->private = NULL; + free(ifp->physaddr); + ifp->physaddr = NULL; + free(ifp->specmib); + ifp->specmib = NULL; STAILQ_FOREACH(map, &mibindexmap_list, link) if (map->mibif == ifp) { @@ -745,8 +746,8 @@ mibif_free(struct mibif *ifp) at = at1; } - free(ifp); + ifp = NULL; mib_if_number--; mib_iftable_last_change = this_tick; }