mirror of
https://github.com/golang/net.git
synced 2026-03-31 02:17:08 +09:00
http2: fix nil panic in typeFrameParser for unassigned frame types
The addition of FramePriorityUpdate (0x10) in RFC 9218 introduced a gap in the frameParsers array indices (0x0a-0x0f). These indices were initialized to nil, causing a panic when typeFrameParser accessed them for unassigned frame types (e.g., ALTSVC 0x0a). This change adds a nil check in typeFrameParser to safely fallback to parseUnknownFrame for these unassigned types, preventing the crash. Fixes golang/go#77652 Change-Id: I14d7ad85afc1eafabc46417a9fff10f9e0a22446 Reviewed-on: https://go-review.googlesource.com/c/net/+/746180 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
This commit is contained in:
@@ -145,7 +145,9 @@ var frameParsers = [...]frameParser{
|
||||
|
||||
func typeFrameParser(t FrameType) frameParser {
|
||||
if int(t) < len(frameParsers) {
|
||||
return frameParsers[t]
|
||||
if f := frameParsers[t]; f != nil {
|
||||
return f
|
||||
}
|
||||
}
|
||||
return parseUnknownFrame
|
||||
}
|
||||
|
||||
@@ -1585,3 +1585,20 @@ func TestReadFrameForHeaderUnexpectedEOF(t *testing.T) {
|
||||
t.Fatalf("ReadFrameForHeader with short body = %v; want io.ErrUnexpectedEOF", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTypeFrameParserHolePanic(t *testing.T) {
|
||||
// Verify that unassigned frame types (0x0a-0x0f) don't panic. golang.org/issue/77652
|
||||
fr, _ := testFramer()
|
||||
if err := fr.WriteRawFrame(FrameType(0x0a), 0, 1, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
f, err := fr.ReadFrame()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, ok := f.(*UnknownFrame); !ok {
|
||||
t.Errorf("got %T; want *UnknownFrame", f)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user