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"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -183,7 +184,7 @@ func (c *connection) write(s string) {
|
||||||
|
|
||||||
func (c *connection) read(desc string) string {
|
func (c *connection) read(desc string) string {
|
||||||
buf := make([]byte, 0)
|
buf := make([]byte, 0)
|
||||||
reader := bufio.NewReader(c.Conn)
|
reader := bufio.NewReader(io.LimitReader(c.Conn, maxRead))
|
||||||
var err error
|
var err error
|
||||||
var conclusion string
|
var conclusion string
|
||||||
if desc == "server hello" {
|
if desc == "server hello" {
|
||||||
|
@ -195,7 +196,7 @@ func (c *connection) read(desc string) string {
|
||||||
var line []byte
|
var line []byte
|
||||||
c.SetReadDeadline(time.Now().Add(timeout * time.Millisecond))
|
c.SetReadDeadline(time.Now().Add(timeout * time.Millisecond))
|
||||||
line, tmpErr := reader.ReadBytes('\n')
|
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 l := string(line); strings.HasPrefix(l, conclusion) {
|
||||||
if strings.HasPrefix(l, conclusion+"OK") {
|
if strings.HasPrefix(l, conclusion+"OK") {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue
Block a user