Skip to content

Commit 2904950

Browse files
mattstaantirez
authored andcommitted
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.
1 parent 3015255 commit 2904950

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/cluster.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,11 @@ int clusterNodeRemoveSlave(clusterNode *master, clusterNode *slave) {
783783

784784
for (j = 0; j < master->numslaves; j++) {
785785
if (master->slaves[j] == slave) {
786-
memmove(master->slaves+j,master->slaves+(j+1),
787-
(master->numslaves-1)-j);
786+
if ((j+1) < master->numslaves) {
787+
int remaining_slaves = (master->numslaves - j) - 1;
788+
memmove(master->slaves+j,master->slaves+(j+1),
789+
(sizeof(*master->slaves) * remaining_slaves));
790+
}
788791
master->numslaves--;
789792
return REDIS_OK;
790793
}

0 commit comments

Comments
 (0)