From 7aa684a354b7f14fb4d1066f0d93399fe25e1806 Mon Sep 17 00:00:00 2001 From: Gaukas Wang Date: Thu, 30 Mar 2023 09:14:55 -0600 Subject: [PATCH] fix: PSK extension w/o session cache crashing (#177) Fixes a bug causing client to crash (SIGSEGV) WHEN PSK extension is set with empty session cache AND server sends HelloRetryRequest. --- u_tls_extensions.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/u_tls_extensions.go b/u_tls_extensions.go index 3bc8826d..4d3b07bb 100644 --- a/u_tls_extensions.go +++ b/u_tls_extensions.go @@ -1859,6 +1859,9 @@ type FakePreSharedKeyExtension struct { } func (e *FakePreSharedKeyExtension) writeToUConn(uc *UConn) error { + if session, ok := uc.config.ClientSessionCache.Get(clientSessionCacheKey(uc.conn.RemoteAddr(), uc.config)); !ok || session == nil { + return nil // don't write the extension if there is no session + } uc.HandshakeState.Hello.PskIdentities = e.PskIdentities uc.HandshakeState.Hello.PskBinders = e.PskBinders return nil