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

Ensure all AVP datatypes copy out of readBuffer #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions diam/datatype/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ func DecodeAddress(b []byte) (Type, error) {
return nil, errors.New("Invalid length for IPv6")
}
default:
return Address(b), nil
tmp := make([]byte, len(b))
copy(tmp, b)
return Address(tmp), nil
}
return Address(b[2:]), nil
tmp := make([]byte, len(b))
copy(tmp, b)
return Address(tmp[2:]), nil
}

// Serialize implements the Type interface.
Expand Down
4 changes: 3 additions & 1 deletion diam/datatype/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ type Grouped []byte

// DecodeGrouped decodes a Grouped data type from byte array.
func DecodeGrouped(b []byte) (Type, error) {
return Grouped(b), nil
tmp := make([]byte, len(b))
copy(tmp, b)
return Grouped(tmp), nil
}

// Serialize implements the Type interface.
Expand Down
4 changes: 3 additions & 1 deletion diam/datatype/ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func DecodeIPv4(b []byte) (Type, error) {
if len(b) != 4 {
return IPv4{0, 0, 0, 0}, nil
}
return IPv4(b), nil
tmp := make([]byte, len(b))
copy(tmp, b)
return IPv4(tmp), nil
}

// Serialize implements the Type interface.
Expand Down
4 changes: 3 additions & 1 deletion diam/datatype/ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func DecodeIPv6(b []byte) (Type, error) {
if len(b) != net.IPv6len {
return IPv6(make(net.IP, net.IPv6len)), nil
}
return IPv6(b), nil
tmp := make([]byte, len(b))
copy(tmp, b)
return IPv6(tmp), nil
}

// Serialize implements the Type interface.
Expand Down
4 changes: 3 additions & 1 deletion diam/datatype/unknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ type Unknown []byte

// DecodeUnknown decodes an Unknown from byte array.
func DecodeUnknown(b []byte) (Type, error) {
return Unknown(b), nil
tmp := make([]byte, len(b))
copy(tmp, b)
return Unknown(tmp), nil
}

// Serialize implements the Type interface.
Expand Down