From 88868d7d8e3c45d0e8835634a4b2345a73861396 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Thu, 13 Oct 2016 20:37:29 +0100 Subject: [PATCH] smtpsrv: Sanitize unknown commands Unknown commands can fill the logs, traces and expvars with a lot of noise; this patch sanitizes them a bit down to 6 bytes, as a compromise to maintain some information for troubleshooting. --- internal/smtpsrv/conn.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/smtpsrv/conn.go b/internal/smtpsrv/conn.go index 24ba3e2..456b42e 100644 --- a/internal/smtpsrv/conn.go +++ b/internal/smtpsrv/conn.go @@ -147,7 +147,6 @@ loop: break } - commandCount.Add(cmd, 1) if cmd == "AUTH" { c.tr.Debugf("-> AUTH ") } else { @@ -187,10 +186,14 @@ loop: c.writeResponse(221, "Be seeing you...") break 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) code = 500 msg = "unknown command" } + commandCount.Add(cmd, 1) if code > 0 { c.tr.Debugf("<- %d %s", code, msg)