git: 5771c3bd1df8 - stable/13 - systat: Fix a bunch of use after frees in fetch_ifstat().

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Wed, 28 Jun 2023 01:33:09 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=5771c3bd1df809113214abbbc3f42d8e05277b4a

commit 5771c3bd1df809113214abbbc3f42d8e05277b4a
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-11-22 19:11:42 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-06-28 01:32:47 +0000

    systat: Fix a bunch of use after frees in fetch_ifstat().
    
    I think this was probably just a typo.  initifstat() continues around
    a similar loop if the mib data fails to fetch, and fetch_ifstat() was
    already using a FOREACH_SAFE loop here so expected to keep going.
    Calling clearifstat() from the fetch routine also seems wrong, and the
    sort_interface_list() call triggered by the existing needsort = 1 will
    itself set needclear to trigger a future clearifstat().
    
    Reported by:    GCC 12 -Wuse-after-free
    Differential Revision:  https://reviews.freebsd.org/D36823
    
    (cherry picked from commit f6fdf9214a657351e78c68aac1888e674c0481f6)
---
 usr.bin/systat/ifstat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/usr.bin/systat/ifstat.c b/usr.bin/systat/ifstat.c
index 82e3429dbfda..d5e43cf1d0aa 100644
--- a/usr.bin/systat/ifstat.c
+++ b/usr.bin/systat/ifstat.c
@@ -299,7 +299,7 @@ fetchifstat(void)
 			SLIST_REMOVE(&curlist, ifp, if_stat, link);
 			free(ifp);
 			needsort = 1;
-			clearifstat();
+			continue;
 		} else if (strcmp(ifp->dev_name, ifp->if_mib.ifmd_name) != 0 ) {
 			/* a device was removed and another one was added */
 			format_device_name(ifp);