github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/prog/size_test.go (about) 1 // Copyright 2016 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package prog 5 6 import ( 7 "bytes" 8 "testing" 9 ) 10 11 func TestAssignSizeRandom(t *testing.T) { 12 target, rs, iters := initTest(t) 13 ct := target.DefaultChoiceTable() 14 for i := 0; i < iters; i++ { 15 p := target.Generate(rs, 10, ct) 16 data0 := p.Serialize() 17 for _, call := range p.Calls { 18 target.assignSizesCall(call) 19 } 20 if data1 := p.Serialize(); !bytes.Equal(data0, data1) { 21 t.Fatalf("different lens assigned, initial:\n%s\nnew:\n%s", data0, data1) 22 } 23 p.Mutate(rs, 10, ct, nil, nil) 24 p.Serialize() 25 for _, call := range p.Calls { 26 target.assignSizesCall(call) 27 } 28 } 29 } 30 31 func TestAssignSize(t *testing.T) { 32 // nolint: lll 33 TestDeserializeHelper(t, "test", "64", func(target *Target, p *Prog) { 34 for _, call := range p.Calls { 35 target.assignSizesCall(call) 36 } 37 }, []DeserializeTest{ 38 { 39 In: "test$length0(&(0x7f0000000000)={0xff, 0x0})", 40 Out: "test$length0(&(0x7f0000000000)={0xff, 0x2})", 41 }, 42 { 43 In: "test$length1(&(0x7f0000001000)={0xff, 0x0})", 44 Out: "test$length1(&(0x7f0000001000)={0xff, 0x4})", 45 }, 46 { 47 In: "test$length2(&(0x7f0000001000)={0xff, 0x0})", 48 Out: "test$length2(&(0x7f0000001000)={0xff, 0x8})", 49 }, 50 { 51 In: "test$length3(&(0x7f0000005000)={0xff, 0x0, 0x0})", 52 Out: "test$length3(&(0x7f0000005000)={0xff, 0x4, 0x2})", 53 }, 54 { 55 In: "test$length4(&(0x7f0000003000)={0x0, 0x0})", 56 Out: "test$length4(&(0x7f0000003000)={0x2, 0x2})", 57 }, 58 { 59 In: "test$length5(&(0x7f0000002000)={0xff, 0x0})", 60 Out: "test$length5(&(0x7f0000002000)={0xff, 0x4})", 61 }, 62 { 63 In: "test$length6(&(0x7f0000002000)={[0xff, 0xff, 0xff, 0xff], 0x0})", 64 Out: "test$length6(&(0x7f0000002000)={[0xff, 0xff, 0xff, 0xff], 0x4})", 65 }, 66 { 67 In: "test$length7(&(0x7f0000003000)={[0xff, 0xff, 0xff, 0xff], 0x0})", 68 Out: "test$length7(&(0x7f0000003000)={[0xff, 0xff, 0xff, 0xff], 0x8})", 69 }, 70 { 71 In: "test$length8(&(0x7f000001f000)={0x00, {0xff, 0x0, 0x00, [0xff, 0xff, 0xff]}, [{0xff, 0x0, 0x00, [0xff, 0xff, 0xff]}], 0x00, 0x0, [0xff, 0xff]})", 72 Out: "test$length8(&(0x7f000001f000)={0x32, {0xff, 0x1, 0x10, [0xff, 0xff, 0xff]}, [{0xff, 0x1, 0x10, [0xff, 0xff, 0xff]}], 0x10, 0x1, [0xff, 0xff]})", 73 }, 74 { 75 In: "test$length9(&(0x7f000001f000)={&(0x7f0000000000/0x5000)=nil, 0x0000})", 76 Out: "test$length9(&(0x7f000001f000)={&(0x7f0000000000/0x5000)=nil, 0x5000})", 77 }, 78 { 79 In: "test$length10(&(0x7f0000000000/0x5000)=nil, 0x0000, 0x0000, 0x0000, 0x0000)", 80 Out: "test$length10(&(0x7f0000000000/0x5000)=nil, 0x5000, 0x5000, 0x2800, 0x1400)", 81 }, 82 { 83 In: "test$length11(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, 0x00)", 84 Out: "test$length11(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, 0x30)", 85 }, 86 { 87 In: "test$length12(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, 0x00)", 88 Out: "test$length12(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, 0x30)", 89 }, 90 { 91 In: "test$length13(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, &(0x7f0000001000)=0x00)", 92 Out: "test$length13(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, &(0x7f0000001000)=0x30)", 93 }, 94 { 95 In: "test$length14(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, &(0x7f0000001000)=0x00)", 96 Out: "test$length14(&(0x7f0000000000)={0xff, 0xff, [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]}, &(0x7f0000001000)=0x30)", 97 }, 98 { 99 In: "test_length15(0xff, 0x0)", 100 Out: "test_length15(0xff, 0x2)", 101 }, 102 { 103 In: "test$length16(&(0x7f0000000000)={[0x42, 0x42], 0xff, 0xff, 0xff, 0xff, 0xff})", 104 Out: "test$length16(&(0x7f0000000000)={[0x42, 0x42], 0x2, 0x10, 0x8, 0x4, 0x2})", 105 }, 106 { 107 In: "test$length17(&(0x7f0000000000)={0x42, 0xff, 0xff, 0xff, 0xff})", 108 Out: "test$length17(&(0x7f0000000000)={0x42, 0x8, 0x4, 0x2, 0x1})", 109 }, 110 { 111 In: "test$length18(&(0x7f0000000000)={0x42, 0xff, 0xff, 0xff, 0xff})", 112 Out: "test$length18(&(0x7f0000000000)={0x42, 0x8, 0x4, 0x2, 0x1})", 113 }, 114 { 115 In: "test$length19(&(0x7f0000000000)={{0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xff}, 0xff, 0xff, 0xff})", 116 Out: "test$length19(&(0x7f0000000000)={{0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x14}, 0x14, 0x14, 0x5})", 117 }, 118 { 119 In: "test$length20(&(0x7f0000000000)={{{0xff, 0xff, 0xff, 0xff}, 0xff, 0xff, 0xff}, 0xff, 0xff})", 120 Out: "test$length20(&(0x7f0000000000)={{{0x4, 0x4, 0x7, 0x9}, 0x7, 0x7, 0x9}, 0x9, 0x9})", 121 }, 122 { 123 In: "test$length21(&(0x7f0000000000)=0x0, 0x0)", 124 Out: "test$length21(&(0x7f0000000000), 0x40)", 125 }, 126 { 127 In: "test$length22(&(0x7f0000000000)='12345', 0x0)", 128 Out: "test$length22(&(0x7f0000000000)='12345', 0x28)", 129 }, 130 { 131 In: "test$length23(&(0x7f0000000000)={0x1, {0x2, 0x0}})", 132 Out: "test$length23(&(0x7f0000000000)={0x1, {0x2, 0x6}})", 133 }, 134 { 135 In: "test$length24(&(0x7f0000000000)={{0x0, {0x0}}, {0x0, {0x0}}})", 136 Out: "test$length24(&(0x7f0000000000)={{0x0, {0x8}}, {0x0, {0x10}}})", 137 }, 138 { 139 In: "test$length26(&(0x7f0000000000), 0x0)", 140 Out: "test$length26(&(0x7f0000000000), 0x8)", 141 }, 142 { 143 In: "test$length27(&(0x7f0000000000), 0x0)", 144 Out: "test$length27(&(0x7f0000000000), 0x2a)", 145 }, 146 { 147 In: "test$length28(&(0x7f0000000000), 0x0)", 148 Out: "test$length28(&(0x7f0000000000), 0x2a)", 149 }, 150 { 151 In: "test$length29(&(0x7f0000000000)={'./a\\x00', './b/c\\x00', 0x0, 0x0, 0x0})", 152 Out: "test$length29(&(0x7f0000000000)={'./a\\x00', './b/c\\x00', 0xa, 0x14, 0x21})", 153 }, 154 { 155 In: "test$length30(&(0x7f0000000000)={{{0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, {'a', 'aaa', 'aaaaa', 'aaaaaa'}, &(0x7f0000000000)={'a', 'aaa', 'aaaaa', 'aaaaaa'}, &(0x7f0000000000)=&(0x7f0000000000)={'a', 'aaa', 'aaaaa', 'aaaaaa'}, 0x0}, 0x0}, 0x0, &(0x7f0000000000)=0x0, 0x0)", 156 Out: "test$length30(&(0x7f0000000000)={{{0x0, 0x18, 0x1, 0x3, 0x5, 0x6}, {'a', 'aaa', 'aaaaa', 'aaaaaa'}, &(0x7f0000000000)={'a', 'aaa', 'aaaaa', 'aaaaaa'}, &(0x7f0000000000)=&(0x7f0000000000)={'a', 'aaa', 'aaaaa', 'aaaaaa'}, 0x2}, 0x4}, 0x40, &(0x7f0000000000)=0x18, 0x2)", 157 }, 158 { 159 In: "test$offsetof0(&(0x7f0000000000)={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0})", 160 Out: "test$offsetof0(&(0x7f0000000000)={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x6, 0x8, 0x10, 0x18, 0x18, 0x20})", 161 }, 162 { 163 // If len target points into squashed argument, value is not updated. 164 In: `test$length_any(&(0x7f0000000000)=ANY=[@ANYBLOB="11"], 0x42)`, 165 }, 166 { 167 In: "test$length32(&(0x7f0000000000)={[0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0], {0x0}, &(0x7f0000000040)={0x0}})", 168 Out: "test$length32(&(0x7f0000000000)={[0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0], {0x8}, &(0x7f0000000040)={0x8}})", 169 }, 170 { 171 In: "test$length33(&(0x7f0000000000)={[0x0, 0x0, 0x0, 0x0], 0x0})", 172 Out: "test$length33(&(0x7f0000000000)={[0x0, 0x0, 0x0, 0x0], 0x4})", 173 }, 174 { 175 In: "test$length34(&(0x7f0000000000)={[0x0, 0x0, 0x0, 0x0], &(0x7f0000000040)=@u1=0x0})", 176 Out: "test$length34(&(0x7f0000000000)={[0x0, 0x0, 0x0, 0x0], &(0x7f0000000040)=@u1=0x4})", 177 }, 178 { 179 In: "test$length35(&(0x7f0000000000)={0x0, {0x5, @void}})", 180 Out: "test$length35(&(0x7f0000000000)={0x4, {0x5}})", 181 }, 182 { 183 In: "test$length35(&(0x7f0000000000)={0x0, {0x1, @value=0x5}})", 184 Out: "test$length35(&(0x7f0000000000)={0x8, {0x1, @value=0x5}})", 185 }, 186 }) 187 }