diff --git a/aurp/aurp_test.go b/aurp/aurp_test.go new file mode 100644 index 0000000..fb7a31e --- /dev/null +++ b/aurp/aurp_test.go @@ -0,0 +1,25 @@ +/* + Copyright 2024 Josh Deprez + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package aurp + +import "testing" + +func FuzzParsePacket(f *testing.F) { + f.Fuzz(func(t *testing.T, p []byte) { + _, _, _ = ParsePacket(p) + }) +} diff --git a/aurp/open.go b/aurp/open.go index 6d990a0..4a33545 100644 --- a/aurp/open.go +++ b/aurp/open.go @@ -109,12 +109,13 @@ func parseOptionTuple(p []byte) (OptionTuple, []byte, error) { return OptionTuple{}, p, fmt.Errorf("insufficient input length %d for option tuple", len(p)) } olen := int(p[0]) + 1 + p = p[1:] if len(p) < olen { return OptionTuple{}, p, fmt.Errorf("insufficient input for option tuple data length %d", olen) } return OptionTuple{ - Type: OptionType(p[1]), - Data: p[2:olen], + Type: OptionType(p[0]), + Data: p[1:olen], }, p[olen:], nil } diff --git a/aurp/zone_info.go b/aurp/zone_info.go index fb83f07..46fb64f 100644 --- a/aurp/zone_info.go +++ b/aurp/zone_info.go @@ -65,9 +65,9 @@ func parseZIReqPacket(p []byte) (*ZIReqPacket, error) { return nil, fmt.Errorf("odd number of bytes %d for networks", len(p)) } c := len(p) / 2 - ns := make([]ddp.Network, 0, c) + ns := make([]ddp.Network, c) for i := range c { - ns[i] = ddp.Network(binary.BigEndian.Uint16(p[i*2:][:2])) + ns[i] = ddp.Network(binary.BigEndian.Uint16(p[2*i:][:2])) } return &ZIReqPacket{ Subcode: SubcodeZoneInfoReq,