author | Alberto Bertogli
<albertito@blitiri.com.ar> 2016-10-10 09:38:38 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2016-10-21 21:13:39 UTC |
parent | aa0486b54e0f16810cdd99b863a011e9c90cb2f7 |
chasquid.go | +10 | -1 |
diff --git a/chasquid.go b/chasquid.go index a747bc6..e7bb41f 100644 --- a/chasquid.go +++ b/chasquid.go @@ -474,6 +474,7 @@ func (c *Conn) Handle() { var cmd, params string var err error + var errCount int loop: for { @@ -538,9 +539,17 @@ loop: if code > 0 { c.tr.Debugf("<- %d %s", code, msg) - // Be verbose about errors, to help troubleshooting. if code >= 400 { + // Be verbose about errors, to help troubleshooting. c.tr.Errorf("%s failed: %d %s", cmd, code, msg) + + errCount++ + if errCount > 10 { + // https://tools.ietf.org/html/rfc5321#section-4.3.2 + c.tr.Errorf("too many errors, breaking connection") + c.writeResponse(421, "too many errors, bye") + break + } } err = c.writeResponse(code, msg)