From: Matt Joiner <anacrolix@gmail.com>
Date: Sun, 20 Feb 2022 05:15:45 +0000 (+1100)
Subject: Quote UDP tracker response error bodies with %#q
X-Git-Tag: v1.41.0
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=fe43ce07c8fe026f82d2f38033b6462013aa5d98;p=btrtrc.git

Quote UDP tracker response error bodies with %#q
---

diff --git a/tracker/udp/client.go b/tracker/udp/client.go
index c7f9392d..0095a912 100644
--- a/tracker/udp/client.go
+++ b/tracker/udp/client.go
@@ -164,7 +164,9 @@ func (cl *Client) request(ctx context.Context, action Action, body []byte) (resp
 			respBody = dr.Body
 			addr = dr.Addr
 		} else if dr.Header.Action == ActionError {
-			err = fmt.Errorf("error response: %s", dr.Body)
+			// I've seen "Connection ID mismatch.^@" in less and other tools, I think they're just
+			// not handling a trailing \x00 nicely.
+			err = fmt.Errorf("error response: %#q", dr.Body)
 		} else {
 			err = fmt.Errorf("unexpected response action %v", dr.Header.Action)
 		}