mirror of
https://github.com/reactos/syzkaller.git
synced 2025-02-10 13:54:15 +00:00
prog: fix isDefaultArg
Test that isDefaultArg returns true for result of DefaultArg. Fix few bugs uncovered by this test.
This commit is contained in:
parent
549f0dc24e
commit
d0790618dc
@ -244,21 +244,6 @@ top:
|
||||
}
|
||||
switch typ.(type) {
|
||||
case *ConstType, *IntType, *FlagsType, *ProcType, *LenType, *CsumType:
|
||||
// Note: temp code to handle transition from proc[20000, 4, int16be]
|
||||
// to int16be[20000:20004] for sock_port. We do our best guess as to
|
||||
// whether it's the old value and if so convert it to new format.
|
||||
// This should be removed soon (Feb 26, 2018).
|
||||
if it, ok := typ.(*IntType); ok && it.Kind == IntRange &&
|
||||
it.RangeBegin == 20000 && it.RangeEnd == 20004 &&
|
||||
it.TypeSize == 2 && it.BigEndian &&
|
||||
it.BitfieldOff == 0 && it.BitfieldLen == 0 &&
|
||||
it.Dir() != DirOut && !debug {
|
||||
if v < 4 {
|
||||
v += 20000
|
||||
} else if v == 0xffffffffffffffff {
|
||||
v = 0
|
||||
}
|
||||
}
|
||||
arg = MakeConstArg(typ, v)
|
||||
case *ResourceType:
|
||||
arg = MakeResultArg(typ, nil, v)
|
||||
|
@ -195,11 +195,11 @@ func TestDeserialize(t *testing.T) {
|
||||
},
|
||||
{
|
||||
input: `syz_test$type_confusion1(&(0x7f0000000000)=@unknown)`,
|
||||
output: `syz_test$type_confusion1(&(0x7f0000000000)=@f1)`,
|
||||
output: `syz_test$type_confusion1(&(0x7f0000000000))`,
|
||||
},
|
||||
{
|
||||
input: `syz_test$type_confusion1(&(0x7f0000000000)=@unknown={0x0, 'abc'}, 0x0)`,
|
||||
output: `syz_test$type_confusion1(&(0x7f0000000000)=@f1)`,
|
||||
output: `syz_test$type_confusion1(&(0x7f0000000000))`,
|
||||
},
|
||||
{
|
||||
input: `syz_test$excessive_fields1(&(0x7f0000000000)=0x0)`,
|
||||
|
10
prog/prog.go
10
prog/prog.go
@ -364,6 +364,9 @@ func (target *Target) defaultArg(t Type) Arg {
|
||||
case *UnionType:
|
||||
return MakeUnionArg(t, target.defaultArg(typ.Fields[0]))
|
||||
case *VmaType:
|
||||
if t.Optional() {
|
||||
return MakeNullPointerArg(t)
|
||||
}
|
||||
return MakeVmaPointerArg(t, 0, target.PageSize)
|
||||
case *PtrType:
|
||||
if t.Optional() {
|
||||
@ -388,7 +391,7 @@ func (target *Target) isDefaultArg(arg Arg) bool {
|
||||
panic(fmt.Sprintf("unknown const type: %#v", t))
|
||||
}
|
||||
case *GroupArg:
|
||||
if !a.fixedInnerSize() {
|
||||
if !a.fixedInnerSize() && len(a.Inner) != 0 {
|
||||
return false
|
||||
}
|
||||
for _, elem := range a.Inner {
|
||||
@ -399,7 +402,7 @@ func (target *Target) isDefaultArg(arg Arg) bool {
|
||||
return true
|
||||
case *UnionArg:
|
||||
t := a.Type().(*UnionType)
|
||||
return a.Option.Type().FieldName() == t.Fields[0].Name() &&
|
||||
return a.Option.Type().FieldName() == t.Fields[0].FieldName() &&
|
||||
target.isDefaultArg(a.Option)
|
||||
case *DataArg:
|
||||
if a.Size() == 0 {
|
||||
@ -425,6 +428,9 @@ func (target *Target) isDefaultArg(arg Arg) bool {
|
||||
}
|
||||
return a.Address == 0 && target.isDefaultArg(a.Res)
|
||||
case *VmaType:
|
||||
if t.Optional() {
|
||||
return a.IsNull()
|
||||
}
|
||||
return a.Address == 0 && a.VmaSize == target.PageSize
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown pointer type: %#v", t))
|
||||
|
@ -23,10 +23,14 @@ func TestGeneration(t *testing.T) {
|
||||
|
||||
func TestDefault(t *testing.T) {
|
||||
target, _, _ := initTest(t)
|
||||
for _, meta := range target.SyscallMap {
|
||||
for _, t := range meta.Args {
|
||||
target.defaultArg(t)
|
||||
}
|
||||
for _, meta := range target.Syscalls {
|
||||
ForeachType(meta, func(typ Type) {
|
||||
arg := target.defaultArg(typ)
|
||||
if !target.isDefaultArg(arg) {
|
||||
t.Errorf("default arg is not default: %s\ntype: %#v\narg: %#v",
|
||||
typ, typ, arg)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ func TestAssignSize(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"syz_test$length28(&(0x7f0000000000), 0x0)",
|
||||
"syz_test$length28(&(0x7f0000000000)=@f1, 0x2a)",
|
||||
"syz_test$length28(&(0x7f0000000000), 0x2a)",
|
||||
},
|
||||
{
|
||||
"syz_test$length29(&(0x7f0000000000)={'./a\\x00', './b/c\\x00', 0x0, 0x0, 0x0})",
|
||||
|
Loading…
x
Reference in New Issue
Block a user