Skip to content

Commit

Permalink
avoid recursion when skipping unknown HTTP/3 frames
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Mar 22, 2022
1 parent b7e93b5 commit a281c48
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions http3/frames.go
Expand Up @@ -14,38 +14,39 @@ type frame interface{}

func parseNextFrame(r io.Reader) (frame, error) {
qr := quicvarint.NewReader(r)
t, err := quicvarint.Read(qr)
if err != nil {
return nil, err
}
l, err := quicvarint.Read(qr)
if err != nil {
return nil, err
}

switch t {
case 0x0:
return &dataFrame{Length: l}, nil
case 0x1:
return &headersFrame{Length: l}, nil
case 0x4:
return parseSettingsFrame(r, l)
case 0x3: // CANCEL_PUSH
fallthrough
case 0x5: // PUSH_PROMISE
fallthrough
case 0x7: // GOAWAY
fallthrough
case 0xd: // MAX_PUSH_ID
fallthrough
case 0xe: // DUPLICATE_PUSH
fallthrough
default:
// skip over unknown frames
if _, err := io.CopyN(ioutil.Discard, qr, int64(l)); err != nil {
for {
t, err := quicvarint.Read(qr)
if err != nil {
return nil, err
}
return parseNextFrame(qr)
l, err := quicvarint.Read(qr)
if err != nil {
return nil, err
}

switch t {
case 0x0:
return &dataFrame{Length: l}, nil
case 0x1:
return &headersFrame{Length: l}, nil
case 0x4:
return parseSettingsFrame(r, l)
case 0x3: // CANCEL_PUSH
fallthrough
case 0x5: // PUSH_PROMISE
fallthrough
case 0x7: // GOAWAY
fallthrough
case 0xd: // MAX_PUSH_ID
fallthrough
case 0xe: // DUPLICATE_PUSH
fallthrough
default:
// skip over unknown frames
if _, err := io.CopyN(ioutil.Discard, qr, int64(l)); err != nil {
return nil, err
}
}
}
}

Expand Down

0 comments on commit a281c48

Please sign in to comment.