From c086df660034f05c570721548843d35bf312db93 Mon Sep 17 00:00:00 2001 From: Lander Verhack Date: Thu, 19 Sep 2024 08:56:22 +0200 Subject: [PATCH] fix: #518 limit length of hardware address on linux --- SharpPcap/LibPcap/Sockaddr.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SharpPcap/LibPcap/Sockaddr.cs b/SharpPcap/LibPcap/Sockaddr.cs index 16ddd558..3f603cd6 100755 --- a/SharpPcap/LibPcap/Sockaddr.cs +++ b/SharpPcap/LibPcap/Sockaddr.cs @@ -97,7 +97,8 @@ internal Sockaddr(IntPtr sockaddrPtr) var saddr_ll = Marshal.PtrToStructure(sockaddrPtr); - var hwAddrBytes = new byte[saddr_ll.sll_halen]; + var hwAddrBytesLength = Math.Min(saddr_ll.sll_halen,(byte)8); // allow max length of 8 bytes (for exotic hardware that doesn't follow the linux standard) + var hwAddrBytes = new byte[hwAddrBytesLength]; Buffer.BlockCopy(saddr_ll.sll_addr, 0, hwAddrBytes, 0, hwAddrBytes.Length); hardwareAddress = new PhysicalAddress(hwAddrBytes); // copy into the PhysicalAddress class }