forked from quic-go/quic-go
fix a crash in the http3.Server when GetConfigForClient returns nil
This commit is contained in:
@@ -140,18 +140,24 @@ func (s *Server) serveImpl(tlsConf *tls.Config, conn net.PacketConn) error {
|
||||
if qconn, ok := ch.Conn.(handshake.ConnWithVersion); ok && qconn.GetQUICVersion() == quic.VersionDraft32 {
|
||||
proto = nextProtoH3Draft32
|
||||
}
|
||||
conf := tlsConf
|
||||
config := tlsConf
|
||||
if tlsConf.GetConfigForClient != nil {
|
||||
getConfigForClient := tlsConf.GetConfigForClient
|
||||
var err error
|
||||
conf, err = getConfigForClient(ch)
|
||||
conf, err := getConfigForClient(ch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if conf != nil {
|
||||
config = conf
|
||||
}
|
||||
}
|
||||
conf = conf.Clone()
|
||||
conf.NextProtos = []string{proto}
|
||||
return conf, nil
|
||||
if config == nil {
|
||||
return nil, nil
|
||||
}
|
||||
config = config.Clone()
|
||||
config.NextProtos = []string{proto}
|
||||
return config, nil
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -616,6 +616,22 @@ var _ = Describe("Server", func() {
|
||||
Expect(conf.NextProtos).To(Equal([]string{"foo", "bar"}))
|
||||
checkGetConfigForClientVersions(receivedConf)
|
||||
})
|
||||
|
||||
It("works if GetConfigForClient returns a nil tls.Config", func() {
|
||||
tlsConf := &tls.Config{GetConfigForClient: func(*tls.ClientHelloInfo) (*tls.Config, error) { return nil, nil }}
|
||||
|
||||
var receivedConf *tls.Config
|
||||
quicListenAddr = func(addr string, conf *tls.Config, _ *quic.Config) (quic.EarlyListener, error) {
|
||||
receivedConf = conf
|
||||
return nil, errors.New("listen err")
|
||||
}
|
||||
s.TLSConfig = tlsConf
|
||||
Expect(s.ListenAndServe()).To(HaveOccurred())
|
||||
conf, err := receivedConf.GetConfigForClient(&tls.ClientHelloInfo{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(conf).ToNot(BeNil())
|
||||
checkGetConfigForClientVersions(receivedConf)
|
||||
})
|
||||
})
|
||||
|
||||
It("closes gracefully", func() {
|
||||
|
||||
Reference in New Issue
Block a user