Skip to content

Commit 6e14e8e

Browse files
committed
syz-cluster: use base-commit hint from patch series for triage
If the series author provided a base-commit, use it. If applying the series against the base-commit fails, fall back to the default method.
1 parent a058b1b commit 6e14e8e

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

pkg/vcs/git.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ func filterEnv() []string {
6868

6969
func (git *gitRepo) Poll(repo, branch string) (*Commit, error) {
7070
git.Reset()
71-
origin, err := git.Run("remote", "get-url", "origin")
72-
if err != nil || strings.TrimSpace(string(origin)) != repo {
71+
origin, err := git.GetURL("origin")
72+
if err != nil || strings.TrimSpace(origin) != repo {
7373
// The repo is here, but it has wrong origin (e.g. repo in config has changed), re-clone.
7474
if err := git.clone(repo, branch); err != nil {
7575
return nil, err
@@ -102,6 +102,14 @@ func (git *gitRepo) Poll(repo, branch string) (*Commit, error) {
102102
return git.Commit(HEAD)
103103
}
104104

105+
func (git Git) GetURL(branch string) (string, error) {
106+
url, err := git.Run("remote", "get-url", branch)
107+
if err != nil {
108+
return "", err
109+
}
110+
return string(url), nil
111+
}
112+
105113
func (git *gitRepo) isNetworkError(output []byte) bool {
106114
// The list is not exhaustive and is meant to be extended over time.
107115
return bytes.Contains(output, []byte("fatal: read error: Connection reset by peer"))
@@ -752,6 +760,24 @@ type BaseCommit struct {
752760
Branches []string
753761
}
754762

763+
func (git Git) TreeAndBranchForCommit(commit string) (tree, branch string, err error) {
764+
const cutOffDays = 60
765+
branchList, err := git.BranchesThatContain(commit, time.Now().Add(-time.Hour*24*cutOffDays))
766+
if err == nil {
767+
return "", "", fmt.Errorf("failed to query branches: %w", err)
768+
}
769+
for _, branch := range branchList {
770+
if strings.Contains(branch.Branch, "/") {
771+
strs := strings.SplitN(branch.Branch, "/", 2)
772+
return strs[0], strs[1], nil
773+
}
774+
}
775+
if len(branchList) != 0 {
776+
return branchList[0].Branch, "", nil
777+
}
778+
return "", "", fmt.Errorf("failed to find a branch containing commit")
779+
}
780+
755781
// BaseForDiff returns a list of commits that could have been the base commit
756782
// for the specified git patch.
757783
// The returned list is minimized to only contain the commits that are represented in different
@@ -830,7 +856,7 @@ func (git Git) BaseForDiff(diff []byte, tracer debugtracer.DebugTracer) ([]*Base
830856
}
831857
// Only focus on branches that are still alive.
832858
const cutOffDays = 60
833-
list, err := git.branchesThatContain(candidate, time.Now().Add(-time.Hour*24*cutOffDays))
859+
list, err := git.BranchesThatContain(candidate, time.Now().Add(-time.Hour*24*cutOffDays))
834860
if err != nil {
835861
return nil, fmt.Errorf("failed to query branches: %w", err)
836862
}
@@ -924,7 +950,7 @@ type branchCommit struct {
924950
Commit string
925951
}
926952

927-
func (git Git) branchesThatContain(commit string, since time.Time) ([]branchCommit, error) {
953+
func (git Git) BranchesThatContain(commit string, since time.Time) ([]branchCommit, error) {
928954
output, err := git.Run(
929955
"branch", "-a",
930956
"--contains", commit,

syz-cluster/workflow/triage-step/main.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,15 @@ func (triager *seriesTriager) GetVerdict(ctx context.Context, sessionID string)
106106

107107
func (triager *seriesTriager) prepareFuzzingTask(ctx context.Context, series *api.Series, trees []*api.Tree,
108108
target *triage.MergedFuzzConfig) (*api.FuzzTask, error) {
109-
result, err := triager.selectFromBlobs(series, trees)
109+
result, err := triager.selectFromBaseCommitHint(series.BaseCommitHint)
110110
if err != nil {
111-
return nil, fmt.Errorf("selection by blob failed: %w", err)
111+
return nil, fmt.Errorf("selection by base-commit failed: %w", err)
112+
}
113+
if result == nil {
114+
result, err = triager.selectFromBlobs(series, trees)
115+
if err != nil {
116+
return nil, fmt.Errorf("selection by blob failed: %w", err)
117+
}
112118
}
113119
if result == nil {
114120
result, err = triager.selectFromList(ctx, series, trees, target)
@@ -168,6 +174,29 @@ func (triager *seriesTriager) selectFromBlobs(series *api.Series, trees []*api.T
168174
}, nil
169175
}
170176

177+
func (triager *seriesTriager) selectFromBaseCommitHint(commit string) (*SelectResult, error) {
178+
triager.Log("attempting to use the base commit provided by author")
179+
git := triager.ops.Git
180+
tree, branch, err := triager.ops.TreeAndBranchForCommit(commit)
181+
if err != nil {
182+
return nil, err
183+
}
184+
url, err := git.GetURL(tree + "/" + branch)
185+
if err != nil {
186+
return nil, err
187+
}
188+
return &SelectResult{
189+
Tree: &api.Tree{
190+
Name: tree,
191+
URL: url,
192+
Branch: branch,
193+
EmailLists: []string{""},
194+
},
195+
Commit: commit,
196+
Arch: fuzzArch,
197+
}, nil
198+
}
199+
171200
func (triager *seriesTriager) selectFromList(ctx context.Context, series *api.Series, trees []*api.Tree,
172201
target *triage.MergedFuzzConfig) (*SelectResult, error) {
173202
selectedTrees := triage.SelectTrees(series, trees)

0 commit comments

Comments
 (0)