git » chasquid » commit 44eb0b9

smtpsrv: Quote unknown commands for debugging

author Alberto Bertogli
2021-06-11 09:03:06 UTC
committer Alberto Bertogli
2021-06-11 09:34:20 UTC
parent 27f4356f67ea24eab2e2cb13f99d15624173c95a

smtpsrv: Quote unknown commands for debugging

When we receive unknown commands, we use the first 6 bytes for
troubleshooting (e.g. put them in traces and exported metrics).

While this is safe, since the different places know how to quote them
properly, it makes things more difficult to analyse, since it's not
uncommon to see be binary blobs.

This patch makes us use the ascii-quoted version instead, to make things
easier to analyze.

internal/smtpsrv/conn.go +1 -1

diff --git a/internal/smtpsrv/conn.go b/internal/smtpsrv/conn.go
index f3d76cb..3397331 100644
--- a/internal/smtpsrv/conn.go
+++ b/internal/smtpsrv/conn.go
@@ -278,7 +278,7 @@ loop:
 		default:
 			// Sanitize it a bit to avoid filling the logs and events with
 			// noisy data. Keep the first 6 bytes for debugging.
-			cmd = fmt.Sprintf("unknown<%.6s>", cmd)
+			cmd = fmt.Sprintf("unknown<%.6q>", cmd)
 			code = 500
 			msg = "5.5.1 Unknown command"
 		}