Skip to content

Commit 2b972bd

Browse files
committed
Validate semver string returned by vsps.
1 parent a6a77d4 commit 2b972bd

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.25.0
55
require (
66
github.com/decred/vspd/types/v3 v3.0.0
77
github.com/gorilla/handlers v1.5.2
8+
golang.org/x/mod v0.37.0
89
)
910

1011
require github.com/felixge/httpsnoop v1.1.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeO
44
github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE=
55
github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE=
66
github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w=
7+
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
8+
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=

service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/decred/vspd/types/v3"
18+
"golang.org/x/mod/semver"
1819
)
1920

2021
// Vsp contains information about a single Voting Service Provider. Includes
@@ -209,6 +210,11 @@ func (s *Service) vspStats(url string, vsp Vsp) error {
209210
return fmt.Errorf("%v: unmarshal failed: %w", infoURL, err)
210211
}
211212

213+
// semver library expects the "v" prefix but vspd does not return it.
214+
if !semver.IsValid("v" + info.VspdVersion) {
215+
return fmt.Errorf("%v: version not valid (%q)", infoURL, info.VspdVersion)
216+
}
217+
212218
vsp.APIVersions = info.APIVersions
213219
vsp.FeePercentage = info.FeePercentage
214220
vsp.Closed = info.VspClosed

0 commit comments

Comments
 (0)