git: 5da13f40eeaa - main - security/wpa_supplicant-devel: Reapply c586ac04eb66

From: Cy Schubert <cy_at_FreeBSD.org>
Date: Tue, 12 Sep 2023 05:53:06 UTC
The branch main has been updated by cy:

URL: https://cgit.FreeBSD.org/ports/commit/?id=5da13f40eeaa4b39b3a9fd41e58d082e954acce6

commit 5da13f40eeaa4b39b3a9fd41e58d082e954acce6
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2023-09-12 05:08:11 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2023-09-12 05:51:07 +0000

    security/wpa_supplicant-devel: Reapply c586ac04eb66
    
    Reapply "Fix 100% CPU when USB wlan NIC removed."
    
    hostapd calls pcap_next(3) to read the next packet off the wlan interface.
    pcap_next() returns a pointer to the packet header but does not indicate
    success or failure. Unfortunately this results in an infinite loop (100%
    CPU) when the wlan device disappears, i.e. when a USB wlan device is
    manually removed or a USB error results in the device removal. However
    pcap_next_ex(3) does return success or failure. To resolve this we use
    pcap_next_ex(), forcing hostapd to exit when the error is encountered.
    
    An error message is printed to syslog or stderr when debugging (-d flag)
    is enabled. Unfortunately wpa_printf() only works when debugging is enabled.
    
    PR:             253608, 273696
    Obtained from:  src 6e5d01124fd4
    Reported by:    Damjan Jovanovic <damjan.jov@gmail.com>,
                    bz (privately)
    MFH:            2023Q3
---
 security/wpa_supplicant-devel/Makefile                   |  2 +-
 .../files/patch-src_l2__packet_l2__packet__freebsd.c     | 16 ++++++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/security/wpa_supplicant-devel/Makefile b/security/wpa_supplicant-devel/Makefile
index 7fc017f967bf..d28ed3db5b82 100644
--- a/security/wpa_supplicant-devel/Makefile
+++ b/security/wpa_supplicant-devel/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	wpa_supplicant
 PORTVERSION=	${COMMIT_DATE}
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	security net
 PKGNAMESUFFIX=	-devel
 
diff --git a/security/wpa_supplicant-devel/files/patch-src_l2__packet_l2__packet__freebsd.c b/security/wpa_supplicant-devel/files/patch-src_l2__packet_l2__packet__freebsd.c
index e256ee3860e1..62365bdc9900 100644
--- a/security/wpa_supplicant-devel/files/patch-src_l2__packet_l2__packet__freebsd.c
+++ b/security/wpa_supplicant-devel/files/patch-src_l2__packet_l2__packet__freebsd.c
@@ -1,5 +1,5 @@
---- src/l2_packet/l2_packet_freebsd.c.orig	2022-01-16 12:51:29.000000000 -0800
-+++ src/l2_packet/l2_packet_freebsd.c	2022-04-14 07:23:26.534960000 -0700
+--- src/l2_packet/l2_packet_freebsd.c.orig	2023-09-05 10:38:47.000000000 -0700
++++ src/l2_packet/l2_packet_freebsd.c	2023-09-11 22:06:24.154851000 -0700
 @@ -8,7 +8,10 @@
   */
  
@@ -12,3 +12,15 @@
  #include <net/bpf.h>
  #endif /* __APPLE__ */
  #include <pcap.h>
+@@ -82,7 +85,10 @@
+ 	unsigned char *buf;
+ 	size_t len;
+ 
+-	packet = pcap_next(pcap, &hdr);
++	if (pcap_next_ex(pcap, &hdr, &packet) == -1) {
++		wpa_printf(MSG_ERROR, "Error reading packet, has device disappeared?");
++		eloop_terminate();
++	}
+ 
+ 	if (!l2->rx_callback || !packet || hdr.caplen < sizeof(*ethhdr))
+ 		return;