ipn: debug zero bytes in IPN json messages

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/905/head
Brad Fitzpatrick 4 years ago committed by Brad Fitzpatrick
parent 8f30fa67aa
commit b4e19b95ed

@ -5,6 +5,7 @@
package ipn package ipn
import ( import (
"bytes"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"errors" "errors"
@ -19,6 +20,8 @@ import (
"tailscale.com/version" "tailscale.com/version"
) )
var jsonEscapedZero = []byte(`\u0000`)
type NoArgs struct{} type NoArgs struct{}
type StartArgs struct { type StartArgs struct {
@ -85,6 +88,9 @@ func (bs *BackendServer) send(n Notify) {
if err != nil { if err != nil {
log.Fatalf("Failed json.Marshal(notify): %v\n%#v", err, n) 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) bs.sendNotifyMsg(b)
} }
@ -204,6 +210,9 @@ func (bc *BackendClient) GotNotifyMsg(b []byte) {
// not interesting // not interesting
return return
} }
if bytes.Contains(b, jsonEscapedZero) {
log.Printf("[unexpected] zero byte in BackendClient.GotNotifyMsg message: %q", b)
}
n := Notify{} n := Notify{}
if err := json.Unmarshal(b, &n); err != nil { if err := json.Unmarshal(b, &n); err != nil {
log.Fatalf("BackendClient.Notify: cannot decode message (length=%d)\n%#v", len(b), string(b)) 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 { if err != nil {
log.Fatalf("Failed json.Marshal(cmd): %v\n%#v\n", err, cmd) 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) bc.sendCommandMsg(b)
} }

Loading…
Cancel
Save