From b4e19b95ede4774e06f708d13dd453bc7595986d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 6 Nov 2020 13:12:52 -0800 Subject: [PATCH] ipn: debug zero bytes in IPN json messages Signed-off-by: Brad Fitzpatrick --- ipn/message.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ipn/message.go b/ipn/message.go index 2ff7f7432..b8ef74a4f 100644 --- a/ipn/message.go +++ b/ipn/message.go @@ -5,6 +5,7 @@ package ipn import ( + "bytes" "encoding/binary" "encoding/json" "errors" @@ -19,6 +20,8 @@ import ( "tailscale.com/version" ) +var jsonEscapedZero = []byte(`\u0000`) + type NoArgs struct{} type StartArgs struct { @@ -85,6 +88,9 @@ func (bs *BackendServer) send(n Notify) { if err != nil { log.Fatalf("Failed json.Marshal(notify): %v\n%#v", err, n) } + if bytes.Contains(b, jsonEscapedZero) { + log.Printf("[unexpected] zero byte in BackendServer.send notify message: %q", b) + } bs.sendNotifyMsg(b) } @@ -204,6 +210,9 @@ func (bc *BackendClient) GotNotifyMsg(b []byte) { // not interesting return } + if bytes.Contains(b, jsonEscapedZero) { + log.Printf("[unexpected] zero byte in BackendClient.GotNotifyMsg message: %q", b) + } n := Notify{} if err := json.Unmarshal(b, &n); err != nil { log.Fatalf("BackendClient.Notify: cannot decode message (length=%d)\n%#v", len(b), string(b)) @@ -230,6 +239,9 @@ func (bc *BackendClient) send(cmd Command) { if err != nil { log.Fatalf("Failed json.Marshal(cmd): %v\n%#v\n", err, cmd) } + if bytes.Contains(b, jsonEscapedZero) { + log.Printf("[unexpected] zero byte in BackendClient.send command: %q", b) + } bc.sendCommandMsg(b) }