Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix parsing OSSFuzz project repos with subfolders and capitalization. #3364

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions clients/ossfuzz/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func (c *client) Search(request clients.SearchRequest) (clients.SearchResponse,
if c.err != nil {
return sr, c.err
}
if c.projects[request.Query] {
projectURI := strings.ToLower(request.Query)
if c.projects[projectURI] {
sr.Hits = 1
}
return sr, nil
Expand Down Expand Up @@ -135,13 +136,14 @@ func fetchStatusFile(uri string) ([]byte, error) {
}

func normalize(rawURL string) (string, error) {
u, err := url.Parse(rawURL)
u, err := url.Parse(strings.ToLower(rawURL))
if err != nil {
return "", fmt.Errorf("url.Parse: %w", err)
}
const splitLen = 2
const splitLen = 3 // corresponding to owner/repo/rest
const minLen = 2 // corresponds to owner/repo
split := strings.SplitN(strings.Trim(u.Path, "/"), "/", splitLen)
if len(split) != splitLen {
if len(split) < minLen {
return "", fmt.Errorf("%s: %w", rawURL, errMalformedURL)
}
org := split[0]
Expand Down
14 changes: 14 additions & 0 deletions clients/ossfuzz/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ func TestClient(t *testing.T) {
wantHit: false,
wantErr: false,
},
{
name: "project with main_repo link longer than owner/repo",
project: "github.com/google/go-cmp",
statusFile: "status.json",
wantHit: true,
wantErr: false,
},
{
name: "project case insensitive",
project: "github.com/FFTW/fftw3",
statusFile: "status.json",
wantHit: true,
wantErr: false,
},
{
name: "non existent status file",
project: "github.com/ossf/scorecard",
Expand Down
8 changes: 8 additions & 0 deletions clients/ossfuzz/testdata/status.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
{
"name": "zydis",
"main_repo": "https://github.com/zyantific/zydis.git"
},
{
"name": "go-cmp",
"main_repo": "https://github.com/google/go-cmp/cmp"
},
{
"name": "fftw3",
"main_repo": "https://github.com/fftw/fftw3.git"
}
]
}