mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 00:50:50 +00:00
Fix potential invalid read past end of array
If array has N elements, we can't read +1 if we are already at N. Also, we need to move elements by their storage size in the array, not just by individual bytes.
This commit is contained in:
parent
30152554ea
commit
29049507ec
@ -783,8 +783,11 @@ int clusterNodeRemoveSlave(clusterNode *master, clusterNode *slave) {
|
|||||||
|
|
||||||
for (j = 0; j < master->numslaves; j++) {
|
for (j = 0; j < master->numslaves; j++) {
|
||||||
if (master->slaves[j] == slave) {
|
if (master->slaves[j] == slave) {
|
||||||
|
if ((j+1) < master->numslaves) {
|
||||||
|
int remaining_slaves = (master->numslaves - j) - 1;
|
||||||
memmove(master->slaves+j,master->slaves+(j+1),
|
memmove(master->slaves+j,master->slaves+(j+1),
|
||||||
(master->numslaves-1)-j);
|
(sizeof(*master->slaves) * remaining_slaves));
|
||||||
|
}
|
||||||
master->numslaves--;
|
master->numslaves--;
|
||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user