Skip to content

Commit

Permalink
fix: sanity check against qtp
Browse files Browse the repository at this point in the history
  • Loading branch information
gaukas committed Jul 20, 2023
1 parent 908c6d6 commit c9bf02c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions quic_clienthello.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ func ParseQUICClientHello(p []byte) (*QUICClientHello, error) {
return nil, err
}

if ch.qtp == nil {
return nil, ErrNotQUICInitialPacket
}

if ch.qtp.ParseError() != nil {
return nil, ch.qtp.ParseError()
}

return &QUICClientHello{ClientHello: *ch}, nil
}

Expand Down
9 changes: 9 additions & 0 deletions quic_transport_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"sort"

"github.com/gaukas/clienthellod/internal/utils"
Expand Down Expand Up @@ -58,15 +59,23 @@ func ParseQUICTransportParameters(extData []byte) *QUICTransportParameters {
for r.Len() > 0 {
paramType, _, qtp.parseError = ReadNextVLI(r)
if qtp.parseError != nil {
qtp.parseError = fmt.Errorf("failed to read transport parameter type: %w", qtp.parseError)
return qtp
}
paramValLen, _, qtp.parseError = ReadNextVLI(r)
if qtp.parseError != nil {
qtp.parseError = fmt.Errorf("failed to read transport parameter value length: %w", qtp.parseError)
return qtp
}

if paramValLen == 0 {
continue // skip empty transport parameter, no need to try to read
}

paramData = make([]byte, paramValLen)
n, qtp.parseError = r.Read(paramData)
if qtp.parseError != nil {
qtp.parseError = fmt.Errorf("failed to read transport parameter value: %w", qtp.parseError)
return qtp
}
if uint64(n) != paramValLen {
Expand Down

0 comments on commit c9bf02c

Please sign in to comment.