Skip to content

Commit

Permalink
security: slot range bound checks
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Dec 15, 2024
1 parent f437f0e commit 4adf99a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (c *clusterClient) _refresh() (err error) {
case c.opt.ReplicaOnly && len(g.nodes) > 1:
nodesCount := len(g.nodes)
for _, slot := range g.slots {
for i := slot[0]; i <= slot[1]; i++ {
for i := slot[0]; i <= slot[1] && i >= 0 && i < 16384; i++ {
pslots[i] = conns[g.nodes[1+util.FastRand(nodesCount-1)].Addr].conn
}
}
Expand All @@ -260,9 +260,8 @@ func (c *clusterClient) _refresh() (err error) {
if len(g.nodes) > 1 {
n := len(g.nodes) - 1
for _, slot := range g.slots {
for i := slot[0]; i <= slot[1]; i++ {
for i := slot[0]; i <= slot[1] && i >= 0 && i < 16384; i++ {
pslots[i] = conns[master].conn

rIndex := c.opt.ReplicaSelector(uint16(i), g.nodes[1:])
if rIndex >= 0 && rIndex < n {
rslots[i] = conns[g.nodes[1+rIndex].Addr].conn
Expand All @@ -273,15 +272,15 @@ func (c *clusterClient) _refresh() (err error) {
}
} else {
for _, slot := range g.slots {
for i := slot[0]; i <= slot[1]; i++ {
for i := slot[0]; i <= slot[1] && i >= 0 && i < 16384; i++ {
pslots[i] = conns[master].conn
rslots[i] = conns[master].conn
}
}
}
default:
for _, slot := range g.slots {
for i := slot[0]; i <= slot[1]; i++ {
for i := slot[0]; i <= slot[1] && i >= 0 && i < 16384; i++ {
pslots[i] = conns[master].conn
}
}
Expand Down

0 comments on commit 4adf99a

Please sign in to comment.