dbus 规范规定:
The value of any string-like type is conceptually 0 or more Unicode codepoints encoded in UTF-8, none of which may be U+0000. The UTF-8 text must be validated strictly: in particular, it must not contain overlong sequences or codepoints above U+10FFFF.
字符串必须是合法的 UTF-8 字符串。
有最直接的例子:
package main
import (
"log"
"pkg.deepin.io/lib/dbus1"
)
func main() {
sessionBus, err := dbus.SessionBus()
if err != nil {
log.Fatal(err)
}
str := string([]byte{0xc3, 0x85, 0xc2, 0xa2, 0xc2, 0xa8, 0xc3, 0xa5, 0xc2, 0x88, 0x80})
log.Println("valid:", utf8.ValidString(str))
var owner string
err = sessionBus.BusObject().Call("org.freedesktop.DBus.GetNameOwner", 0, str).Store(&owner)
if err != nil {
log.Fatal(err)
}
}
运行后收到错误
2019/02/01 09:40:45 valid: false
2019/02/01 09:40:45 read unix @->/run/user/1000/bus: EOF
exit status 1
如果是 emit 信号或回复请求时在线上传递了非法 UTF-8 字符串,则得不到明显的错误,能从 d-feet 上观察到它掉线。