From 081a041108ac037bc9ccfe20449ce5736fea9678 Mon Sep 17 00:00:00 2001 From: Alexander Weinhold Date: Thu, 4 Jan 2018 20:48:36 +0100 Subject: [PATCH] be less retarded about limiting read input * i.e. don't produce integer overflows... --- imap/imap.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imap/imap.go b/imap/imap.go index a28d8ee..d2fa628 100644 --- a/imap/imap.go +++ b/imap/imap.go @@ -4,6 +4,7 @@ import ( "bufio" "crypto/tls" "fmt" + "io" "log" "net/mail" "strconv" @@ -183,7 +184,7 @@ func (c *connection) write(s string) { func (c *connection) read(desc string) string { buf := make([]byte, 0) - reader := bufio.NewReader(c.Conn) + reader := bufio.NewReader(io.LimitReader(c.Conn, maxRead)) var err error var conclusion string if desc == "server hello" { @@ -195,7 +196,7 @@ func (c *connection) read(desc string) string { var line []byte c.SetReadDeadline(time.Now().Add(timeout * time.Millisecond)) line, tmpErr := reader.ReadBytes('\n') - if tmpErr == nil && len(buf)+len(line) <= maxRead { + if tmpErr == nil { if l := string(line); strings.HasPrefix(l, conclusion) { if strings.HasPrefix(l, conclusion+"OK") { break