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

Make AVP decoding goroutine-safe #186

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
6 changes: 4 additions & 2 deletions diam/datatype/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Address []byte

// DecodeAddress decodes an Address data type from byte array.
func DecodeAddress(b []byte) (Type, error) {
d := make([]byte, len(b))
copy(d, b)
if len(b) < 3 {
return nil, fmt.Errorf("Not enough data to make an Address from byte[%d] = %+v", len(b), b)
}
Expand All @@ -32,9 +34,9 @@ func DecodeAddress(b []byte) (Type, error) {
return nil, errors.New("Invalid length for IPv6")
}
default:
return Address(b), nil
return Address(d), nil
}
return Address(b[2:]), nil
return Address(d[2:]), nil
}

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

// DecodeDiameterIdentity decodes a DiameterIdentity from byte array.
func DecodeDiameterIdentity(b []byte) (Type, error) {
return DiameterIdentity(b), nil
d := make([]byte, len(b))
copy(d, b)
return DiameterIdentity(d), nil
}

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

// DecodeDiameterURI decodes a DiameterURI from byte array.
func DecodeDiameterURI(b []byte) (Type, error) {
return DiameterURI(OctetString(b)), nil
d := make([]byte, len(b))
copy(d, b)
return DiameterURI(OctetString(d)), 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
d := make([]byte, len(b))
copy(d, b)
return Grouped(d), nil
}

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

// DecodeIPFilterRule decodes an IPFilterRule data type from byte array.
func DecodeIPFilterRule(b []byte) (Type, error) {
return IPFilterRule(OctetString(b)), nil
d := make([]byte, len(b))
copy(d, b)
return IPFilterRule(OctetString(d)), 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
d := make([]byte, len(b))
copy(d, b)
return IPv4(d), 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
d := make([]byte, len(b))
copy(d, b)
return IPv6(d), nil
}

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

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

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

// DecodeQoSFilterRule decodes an QoSFilterRule data type from byte array.
func DecodeQoSFilterRule(b []byte) (Type, error) {
return QoSFilterRule(OctetString(b)), nil
d := make([]byte, len(b))
copy(d, b)
return QoSFilterRule(OctetString(d)), 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
d := make([]byte, len(b))
copy(d, b)
return Unknown(d), nil
}

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

// DecodeUTF8String decodes an UTF8String data type from byte array.
func DecodeUTF8String(b []byte) (Type, error) {
return UTF8String(OctetString(b)), nil
d := make([]byte, len(b))
copy(d, b)
return UTF8String(OctetString(d)), nil
}

// Serialize implements the Type interface.
Expand Down
Loading