dhcp4d: ensure MQTT topic names are valid UTF-8

https://twitter.com/zekjur/status/1347295676909158400
This commit is contained in:
Michael Stapelberg 2021-01-07 22:52:58 +01:00
parent c30bf38438
commit 3834acfa2b

View File

@ -416,7 +416,9 @@ func newSrv(permDir string) (*srv, error) {
if err != nil {
log.Fatal(err)
}
identifier := latest.Hostname
// MQTT requires valid UTF-8 and some brokers dont cope well with
// invalid UTF-8: https://github.com/fhmq/hmq/issues/104
identifier := strings.ToValidUTF8(latest.Hostname, "")
if identifier == "" {
identifier = latest.HardwareAddr
}