be less retarded about limiting read input
* i.e. don't produce integer overflows...
This commit is contained in:
parent
e20e862889
commit
081a041108
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user