Skip to content

Commit 0b9afc9

Browse files
committed
dhcp4: clone HardwareAddr bytes defensively
I suspect that Go’s net package reuses its buffers and these bytes don’t remain valid forever (perhaps only if the network interfaces of the machine change?). At least that would explain why my DHCP client sent requests with a wrong address.
1 parent 35fcfc1 commit 0b9afc9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

internal/dhcp4/dhcp4.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"errors"
2121
"fmt"
2222
"net"
23+
"slices"
2324
"sync"
2425
"syscall"
2526
"time"
@@ -105,7 +106,9 @@ func (c *Client) ObtainOrRenew() bool {
105106
c.hardwareAddr = c.HWAddr
106107
}
107108
if c.hardwareAddr == nil {
108-
c.hardwareAddr = c.Interface.HardwareAddr
109+
// Defensive slices.Clone because I noticed c.hardwareAddr
110+
// containing an unexpected MAC address (~/2025-08-15-*dhcp4-loss).
111+
c.hardwareAddr = slices.Clone(c.Interface.HardwareAddr)
109112
}
110113
if c.generateXID == nil {
111114
c.generateXID = dhcp4.XIDGenerator(c.hardwareAddr)

0 commit comments

Comments
 (0)