在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

相關文章
相關標籤/搜索