minamijoyo / tfupdate

Update version constraints in your Terraform configurations
MIT License
539 stars 23 forks source link

Fixed a crash when parsing invalid release versions as SemVer #103

Closed minamijoyo closed 9 months ago

minamijoyo commented 9 months ago

Release tags that did not follow SemVer would result in parse errors, but error handling was not being done correctly and resulted in panic by nil references in sortVersions().

For examples: https://github.com/winebarrel/terraform-provider-mysql/releases/tag/mysqlx-v1.9.0-0

$ go run main.go release latest winebarrel/terraform-provider-mysql
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x28 pc=0x100bbbdf4]

goroutine 1 [running]:
github.com/hashicorp/go-version.(*Version).String(0x0)
        /Users/minamijoyo/pkg/mod/github.com/hashicorp/go-version@v1.6.0/version.go:369 +0x34
github.com/hashicorp/go-version.(*Version).Compare(0x0, 0x14000290960)
        /Users/minamijoyo/pkg/mod/github.com/hashicorp/go-version@v1.6.0/version.go:116 +0x24
github.com/hashicorp/go-version.(*Version).LessThan(...)
        /Users/minamijoyo/pkg/mod/github.com/hashicorp/go-version@v1.6.0/version.go:308
github.com/hashicorp/go-version.Collection.Less(...)
        /Users/minamijoyo/pkg/mod/github.com/hashicorp/go-version@v1.6.0/version_collection.go:12
sort.partition({0x1011f3ce8, 0x140004853c8}, 0x0, 0x14, 0x1400022fbe8?)
        /Users/minamijoyo/.asdf/installs/golang/1.21.1/go/src/sort/zsortinterface.go:142 +0xc0
sort.pdqsort({0x1011f3ce8, 0x140004853c8}, 0x18?, 0x1010d93e0?, 0x140004c6101?)
        /Users/minamijoyo/.asdf/installs/golang/1.21.1/go/src/sort/zsortinterface.go:114 +0x1ac
sort.Sort({0x1011f3ce8, 0x140004853c8})
        /Users/minamijoyo/.asdf/installs/golang/1.21.1/go/src/sort/sort.go:51 +0x60
github.com/minamijoyo/tfupdate/release.sortVersions({0x140004c6000?, 0x1011f4610?, 0x1015fa2a0?})
        /Users/minamijoyo/src/github.com/minamijoyo/tfupdate/release/version.go:59 +0x40
github.com/minamijoyo/tfupdate/release.List({0x1011f4610?, 0x1015fa2a0?}, {0x1011f0700?, 0x1400011d9e0?}, 0x1, 0x0)
        /Users/minamijoyo/src/github.com/minamijoyo/tfupdate/release/release.go:41 +0x4c
github.com/minamijoyo/tfupdate/release.Latest({0x1011f4610?, 0x1015fa2a0?}, {0x1011f0700?, 0x1400011d9e0?})
        /Users/minamijoyo/src/github.com/minamijoyo/tfupdate/release/release.go:21 +0x34
github.com/minamijoyo/tfupdate/command.(*ReleaseLatestCommand).Run(0x1400013d200, {0x1400013c030, 0x1, 0x1})
        /Users/minamijoyo/src/github.com/minamijoyo/tfupdate/command/release_latest.go:43 +0x1b8
github.com/mitchellh/cli.(*CLI).Run(0x14000182dc0)
        /Users/minamijoyo/pkg/mod/github.com/mitchellh/cli@v1.0.0/cli.go:255 +0x4a8
main.main()
        /Users/minamijoyo/src/github.com/minamijoyo/tfupdate/main.go:47 +0x204
exit status 2