Sfoglia il codice sorgente

Fix: add missing nil check

interruptSession assumed resumeSession was always called
and stopRunning would always be initialized, but that's
not a safe assumption.
Rod Hynes 8 anni fa
parent
commit
ea76c86246
1 ha cambiato i file con 12 aggiunte e 2 eliminazioni
  1. 12 2
      psiphon/common/tun/tun.go

+ 12 - 2
psiphon/common/tun/tun.go

@@ -445,6 +445,11 @@ func (server *Server) ClientConnected(
 		}
 		}
 	}
 	}
 
 
+	// Note: it's possible that a client disconnects (or reconnects before a
+	// disconnect is detected) and interruptSession is called between
+	// allocateIndex and resumeSession calls here, so interruptSession and
+	// related code must not assume resumeSession has been called.
+
 	server.resumeSession(clientSession, NewChannel(transport, MTU))
 	server.resumeSession(clientSession, NewChannel(transport, MTU))
 
 
 	return nil
 	return nil
@@ -510,17 +515,22 @@ func (server *Server) interruptSession(session *session) {
 
 
 	wasRunning := (session.channel != nil)
 	wasRunning := (session.channel != nil)
 
 
-	session.stopRunning()
+	if session.stopRunning != nil {
+		session.stopRunning()
+	}
+
 	if session.channel != nil {
 	if session.channel != nil {
 		// Interrupt blocked channel read/writes.
 		// Interrupt blocked channel read/writes.
 		session.channel.Close()
 		session.channel.Close()
 	}
 	}
+
 	session.workers.Wait()
 	session.workers.Wait()
+
 	if session.channel != nil {
 	if session.channel != nil {
 		// Don't hold a reference to channel, allowing both it and
 		// Don't hold a reference to channel, allowing both it and
 		// its conn to be garbage collected.
 		// its conn to be garbage collected.
 		// Setting channel to nil must happen after workers.Wait()
 		// Setting channel to nil must happen after workers.Wait()
-		// to ensure no goroutines remains which may access
+		// to ensure no goroutine remains which may access
 		// session.channel.
 		// session.channel.
 		session.channel = nil
 		session.channel = nil
 	}
 	}