Browse Source

Fix panic due to accessing nil conn.RemoteAddr() value

Rod Hynes 9 years ago
parent
commit
e4cc74e694
1 changed files with 7 additions and 1 deletions
  1. 7 1
      psiphon/common/tls/handshake_client.go

+ 7 - 1
psiphon/common/tls/handshake_client.go

@@ -120,7 +120,13 @@ NextCipherSuite:
 	// Session resumption is not allowed if renegotiating because
 	// renegotiation is primarily used to allow a client to send a client
 	// certificate, which would be skipped if session resumption occurred.
-	if sessionCache != nil && c.handshakes == 0 {
+	if sessionCache != nil && c.handshakes == 0 &&
+		// [Psiphon]
+		// Add nil guard as conn.RemoteAddr may be nil. When nil and
+		// when no ServerName for clientSessionCacheKey to use, skip
+		// caching entrely.
+		(c.conn.RemoteAddr() != nil || len(c.config.ServerName) > 0) {
+
 		// Try to resume a previously negotiated TLS session, if
 		// available.
 		cacheKey = clientSessionCacheKey(c.conn.RemoteAddr(), c.config)