Skip to content

Commit

Permalink
fix: avoid infinite loops parsing Maven poms with syntax errors (#294)
Browse files Browse the repository at this point in the history
Resolves #293

Signed-off-by: Spencer Schrock <[email protected]>
  • Loading branch information
spencerschrock authored Mar 14, 2023
1 parent 3d7d6c5 commit b76e5ad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pkg/lockfile/fixtures/maven/invalid-syntax.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<project>
<properties>
<${Id}.version>${project.version}</${Id}.version>
</properties>

<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.42.Final</version>
</dependency>
</dependencies>
</project>
5 changes: 4 additions & 1 deletion pkg/lockfile/parse-maven-lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ func (p *MavenLockProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElemen
p.m = map[string]string{}

for {
t, _ := d.Token()
t, err := d.Token()
if err != nil {
return err
}

switch tt := t.(type) {
case xml.StartElement:
Expand Down
9 changes: 9 additions & 0 deletions pkg/lockfile/parse-maven-lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ func TestParseMavenLock_Invalid(t *testing.T) {
expectPackages(t, packages, []lockfile.PackageDetails{})
}

func TestParseMavenLock_InvalidSyntax(t *testing.T) {
t.Parallel()

packages, err := lockfile.ParseMavenLock("fixtures/maven/invalid-syntax.xml")

expectErrContaining(t, err, "XML syntax error")
expectPackages(t, packages, []lockfile.PackageDetails{})
}

func TestParseMavenLock_NoPackages(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit b76e5ad

Please sign in to comment.