[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Try to protect against crash from dereferencing a NULL in go-proxy



commit f2abf5b60c289103d8661b8e54b3d3aee43a4aaf
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date:   Wed Mar 14 00:15:13 2018 -0400

    Try to protect against crash from dereferencing a NULL in go-proxy
    
    Follow up to ff8f385
    
    Similar to c834c76
---
 proxy-go/snowflake.go | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/proxy-go/snowflake.go b/proxy-go/snowflake.go
index b3b97b3..a12cfb2 100644
--- a/proxy-go/snowflake.go
+++ b/proxy-go/snowflake.go
@@ -71,7 +71,9 @@ func (c *webRTCConn) Read(b []byte) (int, error) {
 func (c *webRTCConn) Write(b []byte) (int, error) {
 	// log.Printf("webrtc Write %d %+q", len(b), string(b))
 	log.Printf("Write %d bytes --> WebRTC", len(b))
-	c.dc.Send(b)
+	if c.dc != nil {
+		c.dc.Send(b)
+	}
 	return len(b), nil
 }
 
@@ -254,12 +256,15 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
 
 		pr, pw := io.Pipe()
 
+		conn := &webRTCConn{pc: pc, dc: dc, pr: pr}
+
 		dc.OnOpen = func() {
 			log.Println("OnOpen channel")
 		}
 		dc.OnClose = func() {
 			log.Println("OnClose channel")
 			pw.Close()
+			conn.dc = nil
 			pc.DeleteDataChannel(dc)
 		}
 		dc.OnMessage = func(msg []byte) {
@@ -273,7 +278,6 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
 			}
 		}
 
-		conn := &webRTCConn{pc: pc, dc: dc, pr: pr}
 		go datachannelHandler(conn, conn.RemoteAddr())
 	}
 

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