1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
|
// Copyright 2017 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package vcs
import (
"fmt"
"os"
"path/filepath"
"sort"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/syzkaller/pkg/debugtracer"
)
func init() {
// Disable sandboxing entirely because we create test repos without sandboxing.
os.Setenv("SYZ_DISABLE_SANDBOXING", "yes")
}
func TestGitRepo(t *testing.T) {
t.Parallel()
baseDir := t.TempDir()
repo1 := CreateTestRepo(t, baseDir, "repo1")
repo2 := CreateTestRepo(t, baseDir, "repo2")
repo := newGitRepo(filepath.Join(baseDir, "repo"), nil, nil)
{
com, err := repo.Poll(repo1.Dir, "master")
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(com, repo1.Commits["master"]["1"]); diff != "" {
t.Fatal(diff)
}
}
{
com, err := repo.CheckoutBranch(repo1.Dir, "branch1")
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(com, repo1.Commits["branch1"]["1"]); diff != "" {
t.Fatal(diff)
}
}
{
want := repo1.Commits["branch1"]["0"]
com, err := repo.CheckoutCommit(repo1.Dir, want.Hash)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(com, want); diff != "" {
t.Fatal(diff)
}
}
{
want := repo2.Commits["branch1"]["0"]
com, err := repo.CheckoutCommit(repo2.Dir, want.Hash)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(com, want); diff != "" {
t.Fatal(diff)
}
}
{
want := repo2.Commits["branch1"]["1"]
com, err := repo.CheckoutCommit(repo2.Dir, want.Hash)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(com, want); diff != "" {
t.Fatal(diff)
}
}
{
com, err := repo.CheckoutBranch(repo2.Dir, "branch2")
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(com, repo2.Commits["branch2"]["1"]); diff != "" {
t.Fatal(diff)
}
}
{
want := repo2.Commits["branch2"]["0"]
com, err := repo.SwitchCommit(want.Hash)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(com, want); diff != "" {
t.Fatal(diff)
}
}
{
type Test struct {
head *Commit
commit *Commit
contains bool
}
tests := []Test{
{repo2.Commits["branch2"]["1"], repo2.Commits["branch2"]["1"], true},
{repo2.Commits["branch2"]["1"], repo2.Commits["branch2"]["0"], true},
{repo2.Commits["branch2"]["1"], repo2.Commits["master"]["0"], true},
{repo2.Commits["branch2"]["1"], repo2.Commits["master"]["1"], false},
{repo2.Commits["branch2"]["1"], repo2.Commits["branch1"]["0"], false},
{repo2.Commits["branch2"]["1"], repo2.Commits["branch1"]["1"], false},
{repo2.Commits["branch2"]["0"], repo2.Commits["branch2"]["0"], true},
{repo2.Commits["branch2"]["0"], repo2.Commits["branch2"]["1"], false},
{repo2.Commits["branch2"]["0"], repo2.Commits["master"]["0"], true},
{repo2.Commits["branch2"]["0"], repo2.Commits["master"]["1"], false},
}
for i, test := range tests {
if _, err := repo.SwitchCommit(test.head.Hash); err != nil {
t.Fatal(err)
}
if contains, err := repo.Contains(test.commit.Hash); err != nil {
t.Fatal(err)
} else if contains != test.contains {
t.Errorf("test %v: got %v, want %v", i, contains, test.contains)
}
}
}
}
func TestMetadata(t *testing.T) {
t.Parallel()
repoDir := t.TempDir()
repo := MakeTestRepo(t, repoDir)
prevHash := ""
for i, test := range metadataTests {
repo.CommitChange(test.description)
com, err := repo.repo.Commit(HEAD)
if err != nil {
t.Fatal(err)
}
checkCommit(t, i, test, com, false)
if len(com.Parents) != 1 || com.Parents[0] != prevHash {
t.Fatalf("bad parents: %+q, expect %q", com.Parents, prevHash)
}
prevHash = com.Hash
}
commits, err := repo.repo.ExtractFixTagsFromCommits("HEAD", extractFixTagsEmail)
if err != nil {
t.Fatal(err)
}
if len(metadataTests) != len(commits) {
t.Fatalf("want %v commits, got %v", len(metadataTests), len(commits))
}
for i, test := range metadataTests {
checkCommit(t, i, test, commits[len(commits)-i-1], true)
for _, title := range []string{test.title, test.title2} {
if title == "" {
continue
}
com, err := repo.repo.GetCommitByTitle(title)
if err != nil {
t.Error(err)
} else if com == nil {
t.Errorf("no commits found by title %q", title)
} else if com.Title != title {
t.Errorf("wrong commit %q found by title %q", com.Title, title)
}
}
}
}
func checkCommit(t *testing.T, idx int, test testCommit, com *Commit, checkTags bool) {
if !checkTags {
return
}
if test.title != com.Title {
t.Errorf("#%v: want title %q, got %q", idx, test.title, com.Title)
}
if test.author != com.Author {
t.Errorf("#%v: want author %q, got %q", idx, test.author, com.Author)
}
if userName != com.AuthorName {
t.Errorf("#%v: want author name %q, got %q", idx, userName, com.Author)
}
if diff := cmp.Diff(test.cc, com.Recipients.GetEmails(To)); diff != "" {
t.Logf("%#v", com.Recipients)
t.Error(diff)
}
if diff := cmp.Diff(test.tags, com.Tags); checkTags && diff != "" {
t.Error(diff)
}
}
type testCommit struct {
description string
title string
title2 string
author string
cc []string
tags []string
}
// nolint: lll
var metadataTests = []testCommit{
{
description: `dashboard/app: bump max repros per bug to 10
Reported-by: syzbot+8e4090902540da8c6e8f@my.mail.com
`,
title: "dashboard/app: bump max repros per bug to 10",
author: userEmail,
cc: []string{userEmail},
tags: []string{"8e4090902540da8c6e8f"},
},
{
description: `executor: remove dead code
Reported-by: syzbot+8e4090902540da8c6e8f@my.mail.com
Reported-by: syzbot <syzbot+a640a0fc325c29c3efcb@my.mail.com>
`,
title: "executor: remove dead code",
author: userEmail,
cc: []string{userEmail},
tags: []string{"8e4090902540da8c6e8f", "a640a0fc325c29c3efcb"},
},
{
description: `pkg/csource: fix string escaping bug
Reported-and-tested-by: syzbot+8e4090902540da8c6e8fa640a0fc325c29c3efcb@my.mail.com
Tested-by: syzbot+4234987263748623784623758235@my.mail.com
`,
title: "pkg/csource: fix string escaping bug",
author: userEmail,
cc: []string{"syzbot+4234987263748623784623758235@my.mail.com", "syzbot+8e4090902540da8c6e8fa640a0fc325c29c3efcb@my.mail.com", userEmail},
tags: []string{"8e4090902540da8c6e8fa640a0fc325c29c3efcb", "4234987263748623784623758235"},
},
{
description: `When freeing a lockf struct that already is part of a linked list, make sure to update the next pointer for the preceding lock. Prevents a double free panic.
ok millert@
Reported-by: syzbot+6dd701dc797b23b8c761@my.mail.com
`,
title: "When freeing a lockf struct that already is part of a linked list, make sure to update the next pointer for the preceding lock. Prevents a double free panic.",
author: userEmail,
cc: []string{userEmail},
tags: []string{"6dd701dc797b23b8c761"},
},
{
description: `ipmr: properly check rhltable_init() return value
commit 8fb472c09b9d ("ipmr: improve hash scalability")
added a call to rhltable_init() without checking its return value.
This problem was then later copied to IPv6 and factorized in commit
0bbbf0e7d0e7 ("ipmr, ip6mr: Unite creation of new mr_table")
Fixes: 8fb472c09b9d ("ipmr: improve hash scalability")
Fixes: 0bbbf0e7d0e7 ("ipmr, ip6mr: Unite creation of new mr_table")
Reported-by: syzbot+6dd701dc797b23b8c761@my.mail.com
`,
title: "ipmr: properly check rhltable_init() return value",
title2: "net-backports: ipmr: properly check rhltable_init() return value",
author: userEmail,
cc: []string{userEmail},
tags: []string{"6dd701dc797b23b8c761"},
},
{
description: `f2fs: sanity check for total valid node blocks
Reported-by: syzbot+bf9253040425feb155ad@my.mail.com
Reported-by: syzbot+bf9253040425feb155ad@my.mail.com
`,
title: "f2fs: sanity check for total valid node blocks",
author: userEmail,
cc: []string{userEmail},
tags: []string{"bf9253040425feb155ad"},
},
{
description: `USB: fix usbmon BUG trigger
Automated tests triggered this by opening usbmon and accessing the
mmap while simultaneously resizing the buffers. This bug was with
us since 2006, because typically applications only size the buffers
once and thus avoid racing. Reported by Kirill A. Shutemov.
Reported-by: <syzbot+f9831b881b3e849829fc@my.mail.com>
Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
`,
title: "USB: fix usbmon BUG trigger",
author: userEmail,
cc: []string{"gregkh@linuxfoundation.org", userEmail, "zaitcev@redhat.com"},
tags: []string{"f9831b881b3e849829fc"},
},
{
description: `Do more sanity checks when accepting socket addresses in routing messages from user land. Reported-by: syzbot+638dbf7851da8e255af5@my.mail.com`,
title: "Do more sanity checks when accepting socket addresses in routing messages from user land. Reported-by: syzbot+638dbf7851da8e255af5@my.mail.com",
author: userEmail,
cc: []string{userEmail},
tags: []string{"638dbf7851da8e255af5"},
},
{
description: `Reported-by: syzbot+3e3c7cfa8093f8de047e@my.mail.com
Comment out an assertion that's now bogus and add a comment.
`,
title: "Reported-by: syzbot+3e3c7cfa8093f8de047e@my.mail.com",
author: userEmail,
cc: []string{userEmail},
tags: []string{"3e3c7cfa8093f8de047e"},
},
}
func TestBisect(t *testing.T) {
t.Parallel()
repoDir := t.TempDir()
repo := MakeTestRepo(t, repoDir)
var commits []string
for i := 0; i < 5; i++ {
repo.CommitChange(fmt.Sprintf("commit %v", i))
com, err := repo.repo.Commit(HEAD)
if err != nil {
t.Fatal(err)
}
commits = append(commits, com.Hash)
t.Logf("%v %v", com.Hash, com.Title)
}
type predFunc func() (BisectResult, error)
type Test struct {
pred predFunc
result []string
}
makePred := func(res1, res2, res3 BisectResult) predFunc {
return func() (BisectResult, error) {
current, err := repo.repo.Commit(HEAD)
if err != nil {
t.Fatal(err)
}
switch current.Hash {
case commits[1]:
return res1, nil
case commits[2]:
return res2, nil
case commits[3]:
return res3, nil
default:
return 0, fmt.Errorf("unknown commit %v", current.Hash)
}
}
}
tests := []Test{
{
// All are bad.
func() (BisectResult, error) {
return BisectBad, nil
},
[]string{commits[1]},
},
{
// All are good.
func() (BisectResult, error) {
return BisectGood, nil
},
[]string{commits[4]},
},
{
// All are skipped.
func() (BisectResult, error) {
return BisectSkip, nil
},
[]string{commits[1], commits[2], commits[3], commits[4]},
},
{
// Some are skipped.
makePred(BisectSkip, BisectSkip, BisectGood),
[]string{commits[4]},
},
{
// Some are skipped.
makePred(BisectGood, BisectSkip, BisectBad),
[]string{commits[2], commits[3]},
},
{
// Some are skipped.
makePred(BisectSkip, BisectSkip, BisectGood),
[]string{commits[4]},
},
}
for i, test := range tests {
t.Logf("TEST %v", i)
result, err := repo.repo.Bisect(commits[4], commits[0], &debugtracer.TestTracer{T: t}, test.pred)
if err != nil {
t.Fatal(err)
}
var got []string
for _, com := range result {
got = append(got, com.Hash)
}
sort.Strings(got) // git result order is non-deterministic (wat)
sort.Strings(test.result)
if diff := cmp.Diff(test.result, got); diff != "" {
t.Logf("result: %+v", got)
t.Fatal(diff)
}
}
}
|