Skip to content

Commit 66803fc

Browse files
committed
MbedSocketClass: add checks on mac address string
1 parent e7ff9d5 commit 66803fc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libraries/SocketWrapper/src/SocketHelpers.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ uint8_t* arduino::MbedSocketClass::macAddress(uint8_t* mac, bool reversed) {
44
const char* mac_str = getNetwork()->get_mac_address();
55
for (int b = 0; b < 6; b++) {
66
uint32_t tmp;
7-
sscanf(&mac_str[b * 2 + (b)], "%02x", (unsigned int*)&tmp);
7+
if (mac_str) {
8+
sscanf(&mac_str[b * 2 + (b)], "%02x", (unsigned int*)&tmp);
9+
} else {
10+
tmp = 0xFF;
11+
}
812
if (reversed) {
913
mac[5 - b] = (uint8_t)tmp;
1014
} else {
@@ -15,7 +19,11 @@ uint8_t* arduino::MbedSocketClass::macAddress(uint8_t* mac, bool reversed) {
1519
}
1620

1721
String arduino::MbedSocketClass::macAddress() {
18-
return String(getNetwork()->get_mac_address());
22+
const char* mac_str = getNetwork()->get_mac_address();
23+
if (!mac_str) {
24+
return String("ff:ff:ff:ff:ff:ff");
25+
}
26+
return String(mac_str);
1927
}
2028

2129
int arduino::MbedSocketClass::hostByName(const char* aHostname, IPAddress& aResult) {

0 commit comments

Comments
 (0)