File tree Expand file tree Collapse file tree 4 files changed +46
-7
lines changed Expand file tree Collapse file tree 4 files changed +46
-7
lines changed Original file line number Diff line number Diff line change 1- // +build gofuzz
2-
31package ndp
42
5- func Fuzz (data []byte ) int {
3+ // fuzz is a shared function for go-fuzz and tests that verify go-fuzz bugs
4+ // are fixed.
5+ func fuzz (data []byte ) int {
66 m , err := ParseMessage (data )
77 if err != nil {
88 return 0
Original file line number Diff line number Diff line change 1+ package ndp
2+
3+ import "testing"
4+
5+ func Test_fuzz (t * testing.T ) {
6+ tests := []struct {
7+ name string
8+ s string
9+ }{
10+ {
11+ name : "parse option length" ,
12+ s : "\x86 000000000000000\x01 \xc0 " ,
13+ },
14+ {
15+ name : "prefix information length" ,
16+ s : "\x86 000000000000000\x03 \x01 00" +
17+ "0000" ,
18+ },
19+ }
20+
21+ for _ , tt := range tests {
22+ t .Run (tt .name , func (t * testing.T ) {
23+ _ = fuzz ([]byte (tt .s ))
24+ })
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ //+build gofuzz
2+
3+ package ndp
4+
5+ func Fuzz (data []byte ) int {
6+ return fuzz (data )
7+ }
Original file line number Diff line number Diff line change @@ -207,6 +207,11 @@ func (pi *PrefixInformation) UnmarshalBinary(b []byte) error {
207207 return err
208208 }
209209
210+ // Guard against incorrect option length.
211+ if raw .Length != piOptLen {
212+ return io .ErrUnexpectedEOF
213+ }
214+
210215 var (
211216 oFlag = (raw .Value [1 ] & 0x80 ) != 0
212217 aFlag = (raw .Value [1 ] & 0x40 ) != 0
@@ -333,16 +338,17 @@ func parseOptions(b []byte) ([]Option, error) {
333338 o = new (RawOption )
334339 }
335340
341+ // Verify that we won't advance beyond the end of the byte slice.
342+ if l > len (b [i :]) {
343+ return nil , io .ErrUnexpectedEOF
344+ }
345+
336346 // Unmarshal at the current offset, up to the expected length.
337347 if err := o .UnmarshalBinary (b [i : i + l ]); err != nil {
338348 return nil , err
339349 }
340350
341- // Verify that we won't advance beyond the end of the byte slice, and
342351 // Advance to the next option's type field.
343- if l > len (b [i :]) {
344- return nil , io .ErrUnexpectedEOF
345- }
346352 i += l
347353
348354 options = append (options , o )
You can’t perform that action at this time.
0 commit comments