commit 3c386e18948a161c925563dfb47212221ee85258
Author: David Fifield <da...@bamsoftware.com>
Date:   Sat Mar 30 12:10:19 2019 -0600

    Read the requestSpec outside of roundTrip.
    
    The difference here is that we don't send a JSON error response as a
    result of errors at this stage.
---
 webextension/native/main.go | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/webextension/native/main.go b/webextension/native/main.go
index cbb48bf..e5f3a74 100644
--- a/webextension/native/main.go
+++ b/webextension/native/main.go
@@ -181,19 +181,10 @@ func sendWebExtensionMessage(w io.Writer, message []byte) 
error {
 // browser. Wait for the browser to send back a webExtensionRoundTripResponse
 // (which actually happens in inFromBrowserLoop--that function uses the ID to
 // find this goroutine again). Return a responseSpec object or an error.
-func roundTrip(conn net.Conn, outToBrowserChan chan<- []byte) (responseSpec, 
error) {
-       err := conn.SetReadDeadline(time.Now().Add(localReadTimeout))
-       if err != nil {
-               return nil, err
-       }
-       req, err := readRequestSpec(conn)
-       if err != nil {
-               return nil, err
-       }
-
+func roundTrip(req requestSpec, outToBrowserChan chan<- []byte) (responseSpec, 
error) {
        // Generate an ID that will allow us to match a response to this 
request.
        idRaw := make([]byte, 8)
-       _, err = rand.Read(idRaw)
+       _, err := rand.Read(idRaw)
        if err != nil {
                return nil, err
        }
@@ -251,7 +242,16 @@ type errorResponseSpec struct {
 func handleConn(conn net.Conn, outToBrowserChan chan<- []byte) error {
        defer conn.Close()
 
-       resp, err := roundTrip(conn, outToBrowserChan)
+       err := conn.SetReadDeadline(time.Now().Add(localReadTimeout))
+       if err != nil {
+               return err
+       }
+       req, err := readRequestSpec(conn)
+       if err != nil {
+               return err
+       }
+
+       resp, err := roundTrip(req, outToBrowserChan)
        if err != nil {
                resp = &errorResponseSpec{Error: err.Error()}
        }



_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to