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(java): Return error when trying to find a remote pom to avoid segfault #7275

Merged
merged 2 commits into from
Jul 31, 2024
Merged
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
15 changes: 7 additions & 8 deletions pkg/dependency/parser/java/pom/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sort"
"strings"

multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-multierror"
"github.com/samber/lo"
"golang.org/x/net/html/charset"
"golang.org/x/xerrors"
Expand Down Expand Up @@ -680,18 +680,15 @@ func (p *Parser) fetchPOMFromRemoteRepositories(paths []string, snapshot bool) (
func (p *Parser) remoteRepoRequest(repo string, paths []string) (*http.Request, error) {
repoURL, err := url.Parse(repo)
if err != nil {
p.logger.Error("URL parse error", log.String("repo", repo))
return nil, nil
return nil, xerrors.Errorf("unable to parse URL: %w", err)
}

paths = append([]string{repoURL.Path}, paths...)
repoURL.Path = path.Join(paths...)

logger := p.logger.With(log.String("host", repoURL.Host), log.String("path", repoURL.Path))
req, err := http.NewRequest("GET", repoURL.String(), http.NoBody)
if err != nil {
logger.Debug("HTTP request failed")
return nil, nil
return nil, xerrors.Errorf("unable to create HTTP request: %w", err)
}
if repoURL.User != nil {
password, _ := repoURL.User.Password()
Expand All @@ -709,7 +706,8 @@ func (p *Parser) fetchPomFileNameFromMavenMetadata(repo string, paths []string)

req, err := p.remoteRepoRequest(repo, mavenMetadataPaths)
if err != nil {
return "", xerrors.Errorf("unable to create request for maven-metadata.xml file")
p.logger.Debug("Unable to create request", log.String("repo", repo), log.Err(err))
return "", nil
}

client := &http.Client{}
Expand Down Expand Up @@ -739,7 +737,8 @@ func (p *Parser) fetchPomFileNameFromMavenMetadata(repo string, paths []string)
func (p *Parser) fetchPOMFromRemoteRepository(repo string, paths []string) (*pom, error) {
req, err := p.remoteRepoRequest(repo, paths)
if err != nil {
return nil, xerrors.Errorf("unable to create request for pom file")
p.logger.Debug("Unable to create request", log.String("repo", repo), log.Err(err))
return nil, nil
}

client := &http.Client{}
Expand Down