Skip to content

Commit

Permalink
Fix non-0 terminated hostname str
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Mar 7, 2022
1 parent b01309c commit 5d90d89
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ void prepareHostname(char* hostname)
hostname[pos] = '-';
pos++;
}
// else do nothing - no leading hyphens and do not include hyphens for all other characters.
pC++;
}
// if the hostname is left blank, use the mac address/default mdns name
if (pos < 6) {
sprintf(hostname + 5, "%*s", 6, escapedMac.c_str() + 6);
} else { //last character must not be hyphen
while (pos > 0 && hostname[pos -1] == '-') {
hostname[pos -1] = 0;
pos--;
}
// else do nothing - no leading hyphens and do not include hyphens for all other characters.
pC++;
}
// if the hostname is left blank, use the mac address/default mdns name
if (pos < 6) {
sprintf(hostname + 5, "%*s", 6, escapedMac.c_str() + 6);
} else { //last character must not be hyphen
hostname[pos] = '\0'; // terminate string
while (pos > 0 && hostname[pos -1] == '-') {
hostname[pos -1] = '\0';
pos--;
}
}
}

//handle Ethernet connection event
Expand Down

0 comments on commit 5d90d89

Please sign in to comment.