From c99cbdbe58f7817a2ee6064e72db25fc1d067b41 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Wed, 21 Sep 2016 16:52:55 +0200 Subject: Emit BufferBlob for array[int8] --- sys/align.go | 7 ++++++- sys/decl.go | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'sys') diff --git a/sys/align.go b/sys/align.go index 6e8563da4..055a433f8 100644 --- a/sys/align.go +++ b/sys/align.go @@ -48,14 +48,19 @@ func addAlignment(t *StructType) { off += pad fields = append(fields, makePad(pad)) } - off += f.Size() fields = append(fields, f) if at, ok := f.(ArrayType); ok && (at.Kind == ArrayRandLen || (at.Kind == ArrayRangeLen && at.RangeBegin != at.RangeEnd)) { varLen = true } + if at, ok := f.(BufferType); ok && (at.Kind == BufferBlobRand || (at.Kind == BufferBlobRange && at.RangeBegin != at.RangeEnd)) { + varLen = true + } if varLen && i != len(t.Fields)-1 { panic("embed array in middle of a struct") } + if !varLen { + off += f.Size() + } } if align != 0 && off%align != 0 && !varLen { pad := align - off%align diff --git a/sys/decl.go b/sys/decl.go index f792f541c..275bbb380 100644 --- a/sys/decl.go +++ b/sys/decl.go @@ -100,7 +100,8 @@ func (t FileoffType) Align() uintptr { type BufferKind int const ( - BufferBlob BufferKind = iota + BufferBlobRand BufferKind = iota + BufferBlobRange BufferString BufferSockaddr BufferFilesystem @@ -110,7 +111,9 @@ const ( type BufferType struct { TypeCommon - Kind BufferKind + Kind BufferKind + RangeBegin uintptr // for BufferBlobRange kind + RangeEnd uintptr // for BufferBlobRange kind } func (t BufferType) Size() uintptr { @@ -119,6 +122,11 @@ func (t BufferType) Size() uintptr { return 14 case BufferAlgName: return 64 + case BufferBlobRange: + if t.RangeBegin == t.RangeEnd { + return t.RangeBegin + } + fallthrough default: panic(fmt.Sprintf("buffer size is not statically known: %v", t.Name())) } -- cgit mrf-deployment From f2d77726c8e7d2662bda0414d55073cd51742ff3 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Fri, 30 Sep 2016 19:14:50 +0200 Subject: Add exec serialize tests for array[int8] --- prog/encodingexec_test.go | 19 +++++++++++++++++++ sys/test.txt | 13 +++++++++++++ 2 files changed, 32 insertions(+) (limited to 'sys') diff --git a/prog/encodingexec_test.go b/prog/encodingexec_test.go index eddda5199..e166e8ae8 100644 --- a/prog/encodingexec_test.go +++ b/prog/encodingexec_test.go @@ -110,6 +110,25 @@ func TestSerializeForExec(t *testing.T) { instrEOF, }, }, + { + "syz_test$array1(&(0x7f0000000000)={0x42, \"0102030405\"})", + []uint64{ + instrCopyin, dataOffset + 0, argConst, 1, 0x42, + instrCopyin, dataOffset + 1, argData, 5, 0x0504030201, + callID("syz_test$array1"), 1, argConst, ptrSize, dataOffset, + instrEOF, + }, + }, + { + "syz_test$array2(&(0x7f0000000000)={0x42, \"aaaaaaaabbbbbbbbccccccccdddddddd\", 0x43})", + []uint64{ + instrCopyin, dataOffset + 0, argConst, 2, 0x42, + instrCopyin, dataOffset + 2, argData, 16, 0xbbbbbbbbaaaaaaaa, 0xddddddddcccccccc, + instrCopyin, dataOffset + 18, argConst, 2, 0x43, + callID("syz_test$array2"), 1, argConst, ptrSize, dataOffset, + instrEOF, + }, + }, } for i, test := range tests { diff --git a/sys/test.txt b/sys/test.txt index a01c6b3c2..6420ed54c 100644 --- a/sys/test.txt +++ b/sys/test.txt @@ -51,6 +51,8 @@ syz_union0 [ # Arrays. syz_test$array0(a0 ptr[in, syz_array_struct]) +syz_test$array1(a0 ptr[in, syz_array_trailing]) +syz_test$array2(a0 ptr[in, syz_array_blob]) # Struct with a variable-length array or variable-length unions. syz_array_struct { @@ -63,3 +65,14 @@ syz_array_union [ f0 int16 f1 int64 ] [varlen] + +syz_array_trailing { + f0 int8 + f1 array[int8, 4:8] +} + +syz_array_blob { + f0 int16 + f1 array[int8, 16] + f2 int16 +} -- cgit mrf-deployment