control/controlclient: diagnose zero bytes from control

Updates #921

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/918/head
Brad Fitzpatrick 4 years ago committed by Brad Fitzpatrick
parent a664aac877
commit fac2b30eff

@ -796,6 +796,8 @@ func decode(res *http.Response, v interface{}, serverKey *wgcfg.Key, mkey *wgcfg
var debugMap, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_MAP")) var debugMap, _ = strconv.ParseBool(os.Getenv("TS_DEBUG_MAP"))
var jsonEscapedZero = []byte(`\u0000`)
func (c *Direct) decodeMsg(msg []byte, v interface{}) error { func (c *Direct) decodeMsg(msg []byte, v interface{}) error {
c.mu.Lock() c.mu.Lock()
serverKey := c.serverKey serverKey := c.serverKey
@ -824,6 +826,10 @@ func (c *Direct) decodeMsg(msg []byte, v interface{}) error {
json.Indent(&buf, b, "", " ") json.Indent(&buf, b, "", " ")
log.Printf("MapResponse: %s", buf.Bytes()) log.Printf("MapResponse: %s", buf.Bytes())
} }
if bytes.Contains(b, jsonEscapedZero) {
log.Printf("[unexpected] zero byte in controlclient.Direct.decodeMsg into %T: %q", v, b)
}
if err := json.Unmarshal(b, v); err != nil { if err := json.Unmarshal(b, v); err != nil {
return fmt.Errorf("response: %v", err) return fmt.Errorf("response: %v", err)
} }
@ -836,6 +842,9 @@ func decodeMsg(msg []byte, v interface{}, serverKey *wgcfg.Key, mkey *wgcfg.Priv
if err != nil { if err != nil {
return err return err
} }
if bytes.Contains(decrypted, jsonEscapedZero) {
log.Printf("[unexpected] zero byte in controlclient decodeMsg into %T: %q", v, decrypted)
}
if err := json.Unmarshal(decrypted, v); err != nil { if err := json.Unmarshal(decrypted, v); err != nil {
return fmt.Errorf("response: %v", err) return fmt.Errorf("response: %v", err)
} }

Loading…
Cancel
Save