From bbc1fe07d7675c26ca6e4ba77c36b98742855757 Mon Sep 17 00:00:00 2001 From: Mingye Chen Date: Fri, 17 Jan 2025 17:54:56 -0700 Subject: [PATCH 1/2] Add panic test --- u_parrot_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 u_parrot_test.go diff --git a/u_parrot_test.go b/u_parrot_test.go new file mode 100644 index 00000000..8e4071cc --- /dev/null +++ b/u_parrot_test.go @@ -0,0 +1,38 @@ +package quic + +import ( + "context" + "net" + "testing" + "time" + + tls "github.com/refraction-networking/utls" +) + +func testDialPanic(t *testing.T, id QUICID) { + + quicSpec, err := QUICID2Spec(id) + if err != nil { + t.Fatal(err) + } + + pktConn, err := net.ListenUDP("udp", nil) + if err != nil { + t.Fatal(err) + } + + tr := &UTransport{Transport: &Transport{Conn: pktConn}, QUICSpec: &quicSpec} + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + tr.Dial(ctx, &net.UDPAddr{IP: net.IP{127, 0, 0, 1}, Port: 1234}, &tls.Config{}, &Config{}) + +} + +func TestDialPanic(t *testing.T) { + + for _, s := range []QUICID{QUICChrome_115, QUICFirefox_116} { + testDialPanic(t, s) + } + +} From a157e2d9dec19b8fe61002618209d01dcd8e51cc Mon Sep 17 00:00:00 2001 From: Mingye Chen Date: Fri, 17 Jan 2025 18:47:42 -0700 Subject: [PATCH 2/2] Fix panic when using QUICRandomFrames --- u_packet_packer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/u_packet_packer.go b/u_packet_packer.go index d9856177..33715407 100644 --- a/u_packet_packer.go +++ b/u_packet_packer.go @@ -250,7 +250,7 @@ func (p *uPacketPacker) MarshalInitialPacketPayload(pl payload, v protocol.Versi return nil, err } - if p.uSpec.InitialPacketSpec.FrameBuilder == nil || len(p.uSpec.InitialPacketSpec.FrameBuilder.(QUICFrames)) == 0 { + if qf, ok := p.uSpec.InitialPacketSpec.FrameBuilder.(QUICFrames); p.uSpec.InitialPacketSpec.FrameBuilder == nil || ok && len(qf) == 0 { qfs := QUICFrames{} for _, frame := range qchframes { if cryptoFrame, ok := frame.(*clienthellod.CRYPTO); ok {