在dbus 线上传递非法utf8 字符串致使与dbus链接被关闭

dbus 规范规定:session

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.unix

字符串必须是合法的 UTF-8 字符串。code

有最直接的例子:字符串

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)
	}
}

运行后收到错误string

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 上观察到它掉线。it

相关文章
相关标签/搜索