summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_userclass.go
diff options
context:
space:
mode:
authorOwen Mooney <owenmooney@fb.com>2018-07-24 05:33:50 -0700
committerOwen Mooney <owenmooney@fb.com>2018-07-24 05:33:50 -0700
commitdbec521a557fffd49f76daab6fc27e0ab77409be (patch)
tree0ee7ed4d039b180daf742f5e331c761fd388a044 /dhcpv4/option_userclass.go
parent75999eab78258d7683ebe6f745dfb392a5db8c5d (diff)
Don't parse past length
Diffstat (limited to 'dhcpv4/option_userclass.go')
-rw-r--r--dhcpv4/option_userclass.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/dhcpv4/option_userclass.go b/dhcpv4/option_userclass.go
index 8aa02d6..7c0aa22 100644
--- a/dhcpv4/option_userclass.go
+++ b/dhcpv4/option_userclass.go
@@ -55,21 +55,22 @@ func ParseOptUserClass(data []byte) (*OptUserClass, error) {
if code != OptionUserClassInformation {
return nil, fmt.Errorf("expected code %v, got %v", OptionUserClassInformation, code)
}
+
+ totalLength := int(data[1])
data = data[2:]
+ if len(data) < totalLength {
+ return nil, fmt.Errorf("ParseOptUserClass: short data: length is %d but got %d bytes",
+ totalLength, len(data))
+ }
- for {
- if len(data) == 0 {
- break
- }
- if len(data) < 1 {
- return nil, errors.New("ParseOptUserClass: short data: missing length field")
- }
- ucLen := int(data[0])
- if len(data) < ucLen+1 {
- return nil, fmt.Errorf("ParseOptUserClass: short data: less than %d bytes", ucLen+2)
+ for i := 0; i < totalLength; {
+ ucLen := int(data[i])
+ opaqueDataIndex := i + ucLen + 1
+ if len(data) < opaqueDataIndex {
+ return nil, fmt.Errorf("ParseOptUserClass: short data: less than %d bytes", opaqueDataIndex)
}
- opt.UserClasses = append(opt.UserClasses, data[1:ucLen+1])
- data = data[1+ucLen:]
+ opt.UserClasses = append(opt.UserClasses, data[i+1:opaqueDataIndex])
+ i += opaqueDataIndex
}
if len(opt.UserClasses) < 1 {
return nil, errors.New("ParseOptUserClass: at least one user class is required")