fixed issues found by go-fuzz

This commit is contained in:
ston1th 2017-11-12 03:09:32 +01:00
commit 15d372ac55
3 changed files with 37 additions and 9 deletions

View file

@ -12,6 +12,15 @@ const (
anys = string(any)
)
func checkFields(s []string, val string) error {
for _, v := range s {
if v == "" {
return errors.New("invalid subfield: " + val)
}
}
return nil
}
type less func(i, j int) bool
func reverse(f less) less {
@ -20,12 +29,18 @@ func reverse(f less) less {
}
}
func index(f Filter, i int, fields []string) (val reflect.Value) {
val = reflect.ValueOf(f.Index(i)).FieldByName(fields[0])
for j := 1; j < len(fields); j++ {
val = val.FieldByName(fields[j])
func walkFields(v reflect.Value, fields []string) reflect.Value {
for i := 0; i < len(fields); i++ {
if v.Kind() != reflect.Struct {
return reflect.ValueOf(nil)
}
v = v.FieldByName(fields[i])
}
return
return v
}
func index(f Filter, i int, fields []string) (val reflect.Value) {
return walkFields(reflect.ValueOf(f.Index(i)).FieldByName(fields[0]), fields[1:])
}
func makeLess(f Filter, fields []string) less {