Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SCTP chunk validation #339

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chunk_payload_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (p *chunkPayloadData) unmarshal(raw []byte) error {
p.beginningFragment = p.flags&payloadDataBeginingFragmentBitmask != 0
p.endingFragment = p.flags&payloadDataEndingFragmentBitmask != 0

if len(raw) < payloadDataHeaderSize {
if len(p.raw) < payloadDataHeaderSize {
return ErrChunkPayloadSmall
}
p.tsn = binary.BigEndian.Uint32(p.raw[0:])
Expand Down
7 changes: 7 additions & 0 deletions error_cause_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import (
"encoding/binary"
"errors"
)

// errorCauseHeader represents the shared header that is shared by all error causes
Expand All @@ -18,6 +19,9 @@
errorCauseHeaderLength = 4
)

// ErrInvalidSCTPChunk is returned when an SCTP chunk is invalid
var ErrInvalidSCTPChunk = errors.New("invalid SCTP chunk")

func (e *errorCauseHeader) marshal() ([]byte, error) {
e.len = uint16(len(e.raw)) + uint16(errorCauseHeaderLength)
raw := make([]byte, e.len)
Expand All @@ -31,6 +35,9 @@
func (e *errorCauseHeader) unmarshal(raw []byte) error {
e.code = errorCauseCode(binary.BigEndian.Uint16(raw[0:]))
e.len = binary.BigEndian.Uint16(raw[2:])
if e.len < errorCauseHeaderLength || int(e.len) > len(raw) {
return ErrInvalidSCTPChunk

Check warning on line 39 in error_cause_header.go

View check run for this annotation

Codecov / codecov/patch

error_cause_header.go#L39

Added line #L39 was not covered by tests
}
valueLength := e.len - errorCauseHeaderLength
e.raw = raw[errorCauseHeaderLength : errorCauseHeaderLength+valueLength]
return nil
Expand Down
8 changes: 7 additions & 1 deletion param_requested_hmac_algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@

const (
hmacResv1 hmacAlgorithm = 0
hmacSHA128 = 1
hmacSHA128 hmacAlgorithm = 1
hmacResv2 hmacAlgorithm = 2
hmacSHA256 hmacAlgorithm = 3
)

// ErrInvalidAlgorithmType is returned if unknown auth algorithm is specified.
var ErrInvalidAlgorithmType = errors.New("invalid algorithm type")

// ErrInvalidChunkLength is returned if the chunk length is invalid.
var ErrInvalidChunkLength = errors.New("invalid chunk length")

func (c hmacAlgorithm) String() string {
switch c {
case hmacResv1:
Expand Down Expand Up @@ -58,6 +61,9 @@
if err != nil {
return nil, err
}
if len(r.raw)%2 == 1 {
return nil, ErrInvalidChunkLength

Check warning on line 65 in param_requested_hmac_algorithm.go

View check run for this annotation

Codecov / codecov/patch

param_requested_hmac_algorithm.go#L65

Added line #L65 was not covered by tests
}

i := 0
for i < len(r.raw) {
Expand Down
Loading