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

Loading…
Cancel
Save