Skip to content

Commit f61725c

Browse files
aqua-botcoheigeaDmitriyLewen
authoredJul 31, 2024··
fix(java): Return error when trying to find a remote pom to avoid segfault [backport: release/v0.54] (#7283)
Co-authored-by: Colm O hEigeartaigh <coheigea@users.noreply.github.com> Co-authored-by: DmitriyLewen <dmitriy.lewen@smartforce.io>
1 parent a7b7117 commit f61725c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed
 

‎pkg/dependency/parser/java/pom/parse.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"sort"
1414
"strings"
1515

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

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

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

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

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

745744
client := &http.Client{}

0 commit comments

Comments
 (0)
Please sign in to comment.