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

Config: Add int conversion upper bound check #13480

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions lxd/api_1.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"math"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -952,6 +953,10 @@ func doAPI10UpdateTriggers(d *Daemon, nodeChanged, clusterChanged map[string]str
asn := clusterConfig.BGPASN()
routerid := nodeConfig.BGPRouterID()

if asn > math.MaxUint32 {
return fmt.Errorf("Cannot convert BGP ASN to uint32: Upper bound exceeded")
}

err := s.BGP.Reconfigure(address, uint32(asn), net.ParseIP(routerid))
if err != nil {
return fmt.Errorf("Failed reconfiguring BGP: %w", err)
Expand Down
29 changes: 25 additions & 4 deletions lxd/cluster/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"math"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -294,9 +295,19 @@ func Accept(state *state.State, gateway *Gateway, name, address string, schema,
Name: name,
}

if count > 1 && voters < int(state.GlobalConfig.MaxVoters()) {
maxVoters := state.GlobalConfig.MaxVoters()
if maxVoters > math.MaxInt {
return nil, fmt.Errorf("Cannot convert maximum voter cluster members to int: Upper bound exceeded")
}

maxStandBy := state.GlobalConfig.MaxStandBy()
if maxStandBy > math.MaxInt {
return nil, fmt.Errorf("Cannot convert maximum standby cluster members to int: Upper bound exceeded")
}

if count > 1 && voters < int(maxVoters) {
node.Role = db.RaftVoter
} else if standbys < int(state.GlobalConfig.MaxStandBy()) {
} else if standbys < int(maxStandBy) {
node.Role = db.RaftStandBy
}

Expand Down Expand Up @@ -1100,10 +1111,20 @@ func newRolesChanges(state *state.State, gateway *Gateway, nodes []db.RaftNode,
}
}

maxVoters := state.GlobalConfig.MaxVoters()
if maxVoters > math.MaxInt {
return nil, fmt.Errorf("Cannot convert maximum voter nodes to int: Upper bound exceeded")
}

maxStandBy := state.GlobalConfig.MaxStandBy()
if maxStandBy > math.MaxInt {
return nil, fmt.Errorf("Cannot convert maximum standby nodes to int: Upper bound exceeded")
}

roles := &app.RolesChanges{
Config: app.RolesConfig{
Voters: int(state.GlobalConfig.MaxVoters()),
StandBys: int(state.GlobalConfig.MaxStandBy()),
Voters: int(maxVoters),
StandBys: int(maxStandBy),
},
State: cluster,
}
Expand Down
Loading