mirror of
https://github.com/reactos/syzkaller.git
synced 2024-10-07 17:13:26 +00:00
sys: replace FilenameType with BufferType{Kind: BufferFilename}
FilenameType is effectively a buffer, there is no need for a separate type.
This commit is contained in:
parent
b40d502736
commit
8b731ed4b7
@ -51,18 +51,19 @@ func newState(ct *ChoiceTable) *state {
|
||||
func (s *state) analyze(c *Call) {
|
||||
foreachArgArray(&c.Args, c.Ret, func(arg, base *Arg, _ *[]*Arg) {
|
||||
switch typ := arg.Type.(type) {
|
||||
case *sys.FilenameType:
|
||||
if arg.Kind == ArgData && arg.Type.Dir() != sys.DirOut {
|
||||
s.files[string(arg.Data)] = true
|
||||
}
|
||||
case *sys.ResourceType:
|
||||
if arg.Type.Dir() != sys.DirIn {
|
||||
s.resources[typ.Desc.Name] = append(s.resources[typ.Desc.Name], arg)
|
||||
// TODO: negative PIDs and add them as well (that's process groups).
|
||||
}
|
||||
case *sys.BufferType:
|
||||
if typ.Kind == sys.BufferString && arg.Kind == ArgData && len(arg.Data) != 0 {
|
||||
s.strings[string(arg.Data)] = true
|
||||
if arg.Type.Dir() != sys.DirOut && arg.Kind == ArgData && len(arg.Data) != 0 {
|
||||
switch typ.Kind {
|
||||
case sys.BufferString:
|
||||
s.strings[string(arg.Data)] = true
|
||||
case sys.BufferFilename:
|
||||
s.files[string(arg.Data)] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -93,6 +93,8 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
|
||||
}
|
||||
case sys.BufferFilesystem:
|
||||
arg.Data = r.filesystem(s)
|
||||
case sys.BufferFilename:
|
||||
arg.Data = []byte(r.filename(s))
|
||||
case sys.BufferSockaddr:
|
||||
arg.Data = r.sockaddr(s)
|
||||
case sys.BufferAlgType:
|
||||
@ -102,9 +104,6 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable) {
|
||||
default:
|
||||
panic("unknown buffer kind")
|
||||
}
|
||||
case *sys.FilenameType:
|
||||
filename := r.filename(s)
|
||||
arg.Data = []byte(filename)
|
||||
case *sys.ArrayType:
|
||||
count := uintptr(0)
|
||||
switch a.Kind {
|
||||
|
@ -85,13 +85,13 @@ func calcStaticPriorities() [][]float32 {
|
||||
noteUsage(0.2, "str")
|
||||
case sys.BufferSockaddr:
|
||||
noteUsage(1.0, "sockaddr")
|
||||
case sys.BufferFilename:
|
||||
noteUsage(1.0, "filename")
|
||||
default:
|
||||
panic("unknown buffer kind")
|
||||
}
|
||||
case *sys.VmaType:
|
||||
noteUsage(0.5, "vma")
|
||||
case *sys.FilenameType:
|
||||
noteUsage(1.0, "filename")
|
||||
case *sys.IntType:
|
||||
switch a.Kind {
|
||||
case sys.IntPlain:
|
||||
|
@ -106,8 +106,6 @@ func (a *Arg) Size() uintptr {
|
||||
case *sys.IntType, *sys.LenType, *sys.FlagsType, *sys.ConstType, *sys.StrConstType,
|
||||
*sys.FileoffType, *sys.ResourceType, *sys.VmaType, *sys.PtrType:
|
||||
return typ.Size()
|
||||
case *sys.FilenameType:
|
||||
return uintptr(len(a.Data))
|
||||
case *sys.BufferType:
|
||||
return uintptr(len(a.Data))
|
||||
case *sys.StructType:
|
||||
|
@ -732,6 +732,9 @@ func (r *randGen) generateArg(s *state, typ sys.Type) (arg *Arg, calls []*Call)
|
||||
case sys.BufferFilesystem:
|
||||
data := r.filesystem(s)
|
||||
return dataArg(a, data), nil
|
||||
case sys.BufferFilename:
|
||||
filename := r.filename(s)
|
||||
return dataArg(a, []byte(filename)), nil
|
||||
case sys.BufferSockaddr:
|
||||
data := r.sockaddr(s)
|
||||
if a.Dir() == sys.DirOut {
|
||||
@ -782,9 +785,6 @@ func (r *randGen) generateArg(s *state, typ sys.Type) (arg *Arg, calls []*Call)
|
||||
v = r.randRangeInt(a.RangeBegin, a.RangeEnd)
|
||||
}
|
||||
return constArg(a, v), nil
|
||||
case *sys.FilenameType:
|
||||
filename := r.filename(s)
|
||||
return dataArg(a, []byte(filename)), nil
|
||||
case *sys.ArrayType:
|
||||
count := uintptr(0)
|
||||
switch a.Kind {
|
||||
|
@ -76,12 +76,6 @@ func (c *Call) validate(ctx *validCtx) error {
|
||||
default:
|
||||
return fmt.Errorf("syscall %v: fd arg '%v' has bad kind %v", c.Meta.Name, typ.Name(), arg.Kind)
|
||||
}
|
||||
case *sys.FilenameType:
|
||||
switch arg.Kind {
|
||||
case ArgData:
|
||||
default:
|
||||
return fmt.Errorf("syscall %v: filename arg '%v' has bad kind %v", c.Meta.Name, typ.Name(), arg.Kind)
|
||||
}
|
||||
case *sys.StructType, *sys.ArrayType:
|
||||
switch arg.Kind {
|
||||
case ArgGroup:
|
||||
|
15
sys/decl.go
15
sys/decl.go
@ -118,6 +118,7 @@ const (
|
||||
BufferBlobRand BufferKind = iota
|
||||
BufferBlobRange
|
||||
BufferString
|
||||
BufferFilename
|
||||
BufferSockaddr
|
||||
BufferFilesystem
|
||||
BufferAlgType
|
||||
@ -251,18 +252,6 @@ func (t *IntType) Align() uintptr {
|
||||
return t.Size()
|
||||
}
|
||||
|
||||
type FilenameType struct {
|
||||
TypeCommon
|
||||
}
|
||||
|
||||
func (t *FilenameType) Size() uintptr {
|
||||
panic("filename size is not statically known")
|
||||
}
|
||||
|
||||
func (t *FilenameType) Align() uintptr {
|
||||
return 1
|
||||
}
|
||||
|
||||
type ArrayKind int
|
||||
|
||||
const (
|
||||
@ -513,7 +502,7 @@ func ForeachType(meta *Call, f func(Type)) {
|
||||
}
|
||||
case *ResourceType, *FileoffType, *BufferType,
|
||||
*VmaType, *LenType, *FlagsType, *ConstType,
|
||||
*StrConstType, *IntType, *FilenameType:
|
||||
*StrConstType, *IntType:
|
||||
default:
|
||||
panic("unknown type")
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ func generateArg(
|
||||
ptrCommonHdr := common()
|
||||
dir = "in"
|
||||
opt = false
|
||||
fmt.Fprintf(out, "&PtrType{%v, Type: &FilenameType{%v}}", ptrCommonHdr, common())
|
||||
fmt.Fprintf(out, "&PtrType{%v, Type: &BufferType{%v, Kind: BufferFilename}}", ptrCommonHdr, common())
|
||||
case "array":
|
||||
if len(a) != 1 && len(a) != 2 {
|
||||
failf("wrong number of arguments for %v arg %v, want 1 or 2, got %v", typ, name, len(a))
|
||||
|
Loading…
Reference in New Issue
Block a user