Skip to content

Commit 7a10967

Browse files
committed
ethernet: fix setMACAddress
1 parent c9cfdeb commit 7a10967

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

libraries/SocketWrapper/SocketHelpers.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,17 @@ IPAddress NetworkInterface::dnsServerIP() {
116116
}
117117

118118
void NetworkInterface::setMACAddress(const uint8_t *mac) {
119-
struct net_eth_addr new_mac;
120119
struct ethernet_req_params params = {0};
121120

122-
memcpy(&params.mac_address, &new_mac, sizeof(struct net_eth_addr));
121+
if (mac == nullptr) {
122+
LOG_ERR("MAC address pointer is null");
123+
return;
124+
}
125+
memcpy(&params.mac_address, mac, sizeof(struct net_eth_addr));
126+
if (!net_eth_is_addr_valid(&params.mac_address)) {
127+
LOG_ERR("Invalid MAC address");
128+
return;
129+
}
123130

124131
net_if_down(netif); // Ensure the interface is down before changing the MAC address
125132

0 commit comments

Comments
 (0)