Skip to content

Commit 2a2f5a0

Browse files
spencerschrockashearin
authored andcommitted
🐛 Fix parsing OSSFuzz project repos with subfolders and capitalization. (ossf#3364)
* Split main_repo with correct number of parts. Add go-cmp test. Signed-off-by: Spencer Schrock <sschrock@google.com> * force repo to lowercase when comparing names. Signed-off-by: Spencer Schrock <sschrock@google.com> --------- Signed-off-by: Spencer Schrock <sschrock@google.com> Signed-off-by: Allen Shearin <allen.p.shearin@gmail.com>
1 parent 07341b1 commit 2a2f5a0

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

clients/ossfuzz/client.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ func (c *client) Search(request clients.SearchRequest) (clients.SearchResponse,
8383
if c.err != nil {
8484
return sr, c.err
8585
}
86-
if c.projects[request.Query] {
86+
projectURI := strings.ToLower(request.Query)
87+
if c.projects[projectURI] {
8788
sr.Hits = 1
8889
}
8990
return sr, nil
@@ -135,13 +136,14 @@ func fetchStatusFile(uri string) ([]byte, error) {
135136
}
136137

137138
func normalize(rawURL string) (string, error) {
138-
u, err := url.Parse(rawURL)
139+
u, err := url.Parse(strings.ToLower(rawURL))
139140
if err != nil {
140141
return "", fmt.Errorf("url.Parse: %w", err)
141142
}
142-
const splitLen = 2
143+
const splitLen = 3 // corresponding to owner/repo/rest
144+
const minLen = 2 // corresponds to owner/repo
143145
split := strings.SplitN(strings.Trim(u.Path, "/"), "/", splitLen)
144-
if len(split) != splitLen {
146+
if len(split) < minLen {
145147
return "", fmt.Errorf("%s: %w", rawURL, errMalformedURL)
146148
}
147149
org := split[0]

clients/ossfuzz/client_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ func TestClient(t *testing.T) {
5656
wantHit: false,
5757
wantErr: false,
5858
},
59+
{
60+
name: "project with main_repo link longer than owner/repo",
61+
project: "github.com/google/go-cmp",
62+
statusFile: "status.json",
63+
wantHit: true,
64+
wantErr: false,
65+
},
66+
{
67+
name: "project case insensitive",
68+
project: "github.com/FFTW/fftw3",
69+
statusFile: "status.json",
70+
wantHit: true,
71+
wantErr: false,
72+
},
5973
{
6074
name: "non existent status file",
6175
project: "github.com/ossf/scorecard",

clients/ossfuzz/testdata/status.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
{
2020
"name": "zydis",
2121
"main_repo": "https://github.com/zyantific/zydis.git"
22+
},
23+
{
24+
"name": "go-cmp",
25+
"main_repo": "https://github.com/google/go-cmp/cmp"
26+
},
27+
{
28+
"name": "fftw3",
29+
"main_repo": "https://github.com/fftw/fftw3.git"
2230
}
2331
]
2432
}

0 commit comments

Comments
 (0)