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 {
|
if qconn, ok := ch.Conn.(handshake.ConnWithVersion); ok && qconn.GetQUICVersion() == quic.VersionDraft32 {
|
||||||
proto = nextProtoH3Draft32
|
proto = nextProtoH3Draft32
|
||||||
}
|
}
|
||||||
conf := tlsConf
|
config := tlsConf
|
||||||
if tlsConf.GetConfigForClient != nil {
|
if tlsConf.GetConfigForClient != nil {
|
||||||
getConfigForClient := tlsConf.GetConfigForClient
|
getConfigForClient := tlsConf.GetConfigForClient
|
||||||
var err error
|
var err error
|
||||||
conf, err = getConfigForClient(ch)
|
conf, err := getConfigForClient(ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if conf != nil {
|
||||||
|
config = conf
|
||||||
|
}
|
||||||
}
|
}
|
||||||
conf = conf.Clone()
|
if config == nil {
|
||||||
conf.NextProtos = []string{proto}
|
return nil, nil
|
||||||
return conf, 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"}))
|
Expect(conf.NextProtos).To(Equal([]string{"foo", "bar"}))
|
||||||
checkGetConfigForClientVersions(receivedConf)
|
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() {
|
It("closes gracefully", func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user