From 243c4bf89cf66d2cda30d27850eb48bb82eb0863 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Thu, 19 Jan 2017 20:23:57 +0100 Subject: prog: fix bytesizeN for nonarray fields --- prog/analysis.go | 9 ++++++++- prog/size_test.go | 12 ++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'prog') diff --git a/prog/analysis.go b/prog/analysis.go index 99f947df2..a4f399f98 100644 --- a/prog/analysis.go +++ b/prog/analysis.go @@ -166,7 +166,11 @@ func generateSize(arg *Arg, lenType *sys.LenType) *Arg { return constArg(lenType, uintptr(len(arg.Inner))) } default: - return constArg(lenType, arg.Size()) + if lenType.ByteSize != 0 { + return constArg(lenType, arg.Size()/lenType.ByteSize) + } else { + return constArg(lenType, arg.Size()) + } } } @@ -192,6 +196,9 @@ func assignSizes(args []*Arg) { if typ, ok := arg.Type.(*sys.LenType); ok { if typ.Buf == "parent" { arg.Val = parentSize + if typ.ByteSize != 0 { + arg.Val /= typ.ByteSize + } continue } diff --git a/prog/size_test.go b/prog/size_test.go index d5aaaaf12..0b7e5fb98 100644 --- a/prog/size_test.go +++ b/prog/size_test.go @@ -107,8 +107,16 @@ func TestAssignSize(t *testing.T) { "syz_test$length16(&(0x7f0000000000)={[0x42, 0x42], 0x2, 0x10, 0x8, 0x4, 0x2})", }, { - "syz_test$length17(&(0x7f0000000000)={{0x42, 0x42, 0x42, 0xff}, 0xff, 0xff})", - "syz_test$length17(&(0x7f0000000000)={{0x42, 0x42, 0x42, 0x8}, 0x8, 0x8})", + "syz_test$length17(&(0x7f0000000000)={0x42, 0xff, 0xff, 0xff, 0xff})", + "syz_test$length17(&(0x7f0000000000)={0x42, 0x8, 0x4, 0x2, 0x1})", + }, + { + "syz_test$length18(&(0x7f0000000000)={0x42, 0xff, 0xff, 0xff, 0xff})", + "syz_test$length18(&(0x7f0000000000)={0x42, 0x8, 0x4, 0x2, 0x1})", + }, + { + "syz_test$length19(&(0x7f0000000000)={{0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xff}, 0xff, 0xff, 0xff})", + "syz_test$length19(&(0x7f0000000000)={{0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x14}, 0x14, 0x14, 0x5})", }, } -- cgit mrf-deployment