commit 254e6b9a3d404d1f2bde5e12a2e6d1cf7a08dc80 Author: Cecylia Bocovich cohosh@torproject.org Date: Tue May 28 13:14:18 2019 -0400
Simplified limitedReader by reading one extra byte --- client/lib/rendezvous.go | 13 +++---------- proxy-go/snowflake.go | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-)
diff --git a/client/lib/rendezvous.go b/client/lib/rendezvous.go index 7f03d13..cd26f6e 100644 --- a/client/lib/rendezvous.go +++ b/client/lib/rendezvous.go @@ -67,18 +67,11 @@ func NewBrokerChannel(broker string, front string, transport http.RoundTripper) }
func limitedRead(r io.Reader, limit int64) ([]byte, error) { - p, err := ioutil.ReadAll(&io.LimitedReader{r, limit}) + p, err := ioutil.ReadAll(&io.LimitedReader{r, limit + 1}) if err != nil { return p, err - } - - //Check to see if limit was exceeded - var tmp [1]byte - _, err = io.ReadFull(r, tmp[:]) - if err == io.EOF { - err = nil - } else if err == nil { - err = io.ErrUnexpectedEOF + } else if int64(len(p)) == limit+1 { + return p[0:limit], io.ErrUnexpectedEOF } return p, err } diff --git a/proxy-go/snowflake.go b/proxy-go/snowflake.go index ececda3..27eb9a3 100644 --- a/proxy-go/snowflake.go +++ b/proxy-go/snowflake.go @@ -140,18 +140,11 @@ func genSessionID() string { }
func limitedRead(r io.Reader, limit int64) ([]byte, error) { - p, err := ioutil.ReadAll(&io.LimitedReader{r, limit}) + p, err := ioutil.ReadAll(&io.LimitedReader{r, limit + 1}) if err != nil { return p, err - } - - //Check to see if limit was exceeded - var tmp [1]byte - _, err = io.ReadFull(r, tmp[:]) - if err == io.EOF { - err = nil - } else if err == nil { - err = io.ErrUnexpectedEOF + } else if int64(len(p)) == limit+1 { + return p[0:limit], io.ErrUnexpectedEOF } return p, err }
tor-commits@lists.torproject.org