From b95f468e9e85a98bd2bc4d817f5c1a8451fa928b Mon Sep 17 00:00:00 2001 From: "Teppei.F" <37261985+T3pp31@users.noreply.github.com> Date: Mon, 18 Aug 2025 08:14:14 +0900 Subject: [PATCH 1/2] Update native.py --- scapy/arch/windows/native.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scapy/arch/windows/native.py b/scapy/arch/windows/native.py index 61cfa8beb8a..b2b457da615 100644 --- a/scapy/arch/windows/native.py +++ b/scapy/arch/windows/native.py @@ -222,7 +222,7 @@ def recv_raw(self, x=MTU): def close(self): # type: () -> None - if not self.closed and self.promisc: + if not self.closed and self.promisc and hasattr(self, 'ins'): self.ins.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF) super(L3WinSocket, self).close() From 5b1c1751243467c4ceeb231c5749711fd9494799 Mon Sep 17 00:00:00 2001 From: "Teppei.F" <37261985+T3pp31@users.noreply.github.com> Date: Mon, 18 Aug 2025 08:19:29 +0900 Subject: [PATCH 2/2] Add test for L3WinSocket.close() with partial init Introduces a test to ensure L3WinSocket.close() does not raise AttributeError when called on a partially initialized object. This improves robustness by verifying correct handling of incomplete initialization. --- test/windows.uts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/windows.uts b/test/windows.uts index 59202833331..394376be0c2 100644 --- a/test/windows.uts +++ b/test/windows.uts @@ -117,6 +117,27 @@ def _test(): retry_test(_test) += Test L3WinSocket close() with partial initialization +~ windows + +from scapy.arch.windows.native import L3WinSocket +import socket + +# Create partially initialized L3WinSocket +ws = object.__new__(L3WinSocket) +ws.closed = False +ws.promisc = True +# Note: ws.ins is intentionally not set + +# This should not raise AttributeError +try: + ws.close() + test_passed = True +except AttributeError: + test_passed = False + +assert test_passed, "L3WinSocket.close() raised AttributeError on partially initialized object" + = Leave native mode conf.use_pcap = True