From 1aa05851ff82bf433200073c70c612cc0228859f Mon Sep 17 00:00:00 2001 From: Ping Xie Date: Tue, 30 Apr 2024 22:50:58 -0700 Subject: [PATCH] Fix a memory corruption bug Signed-off-by: Ping Xie --- src/cluster_legacy.c | 2 +- src/commands.def | 2 +- src/replication.c | 2 +- tests/unit/cluster/slot-migration.tcl | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index 68c7369f1e..c6ead92662 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -6244,7 +6244,7 @@ bool clusterParseSetSlotCommand(client *c, int *slot, clusterNode **node, int *t t = (int)strtol(c->argv[i+1]->ptr, NULL, 10); decrRefCount(c->argv[i]); decrRefCount(c->argv[i+1]); - memmove(c->argv[i], c->argv[i+2], c->argc-i-2); + memmove(&c->argv[i], &c->argv[i+2], c->argc-i-2); c->argc -= 2; continue; } diff --git a/src/commands.def b/src/commands.def index e1eb6350d9..fa5f6df9e8 100644 --- a/src/commands.def +++ b/src/commands.def @@ -969,7 +969,7 @@ struct COMMAND_STRUCT CLUSTER_Subcommands[] = { {MAKE_CMD("reset","Resets a node.","O(N) where N is the number of known nodes. The command may execute a FLUSHALL as a side effect.","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_RESET_History,0,CLUSTER_RESET_Tips,0,clusterCommand,-2,CMD_ADMIN|CMD_STALE|CMD_NOSCRIPT,0,CLUSTER_RESET_Keyspecs,0,NULL,1),.args=CLUSTER_RESET_Args}, {MAKE_CMD("saveconfig","Forces a node to save the cluster configuration to disk.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SAVECONFIG_History,0,CLUSTER_SAVECONFIG_Tips,0,clusterCommand,2,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,CLUSTER_SAVECONFIG_Keyspecs,0,NULL,0)}, {MAKE_CMD("set-config-epoch","Sets the configuration epoch for a new node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SET_CONFIG_EPOCH_History,0,CLUSTER_SET_CONFIG_EPOCH_Tips,0,clusterCommand,3,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE,0,CLUSTER_SET_CONFIG_EPOCH_Keyspecs,0,NULL,1),.args=CLUSTER_SET_CONFIG_EPOCH_Args}, -{MAKE_CMD("setslot","Binds a hash slot to a node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SETSLOT_History,0,CLUSTER_SETSLOT_Tips,0,clusterCommand,-4,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE|CMD_MAY_REPLICATE,0,CLUSTER_SETSLOT_Keyspecs,0,NULL,2),.args=CLUSTER_SETSLOT_Args}, +{MAKE_CMD("setslot","Binds a hash slot to a node.","O(1)","3.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SETSLOT_History,0,CLUSTER_SETSLOT_Tips,0,clusterCommand,-4,CMD_NO_ASYNC_LOADING|CMD_ADMIN|CMD_STALE|CMD_WRITE,0,CLUSTER_SETSLOT_Keyspecs,0,NULL,2),.args=CLUSTER_SETSLOT_Args}, {MAKE_CMD("shards","Returns the mapping of cluster slots to shards.","O(N) where N is the total number of cluster nodes","7.0.0",CMD_DOC_NONE,NULL,NULL,"cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SHARDS_History,0,CLUSTER_SHARDS_Tips,1,clusterCommand,2,CMD_LOADING|CMD_STALE,0,CLUSTER_SHARDS_Keyspecs,0,NULL,0)}, {MAKE_CMD("slaves","Lists the replica nodes of a master node.","O(N) where N is the number of replicas.","3.0.0",CMD_DOC_DEPRECATED,"`CLUSTER REPLICAS`","5.0.0","cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SLAVES_History,0,CLUSTER_SLAVES_Tips,1,clusterCommand,3,CMD_ADMIN|CMD_STALE,0,CLUSTER_SLAVES_Keyspecs,0,NULL,1),.args=CLUSTER_SLAVES_Args}, {MAKE_CMD("slots","Returns the mapping of cluster slots to nodes.","O(N) where N is the total number of Cluster nodes","3.0.0",CMD_DOC_DEPRECATED,"`CLUSTER SHARDS`","7.0.0","cluster",COMMAND_GROUP_CLUSTER,CLUSTER_SLOTS_History,2,CLUSTER_SLOTS_Tips,1,clusterCommand,2,CMD_LOADING|CMD_STALE,0,CLUSTER_SLOTS_Keyspecs,0,NULL,0)}, diff --git a/src/replication.c b/src/replication.c index e457787142..258ff789f0 100644 --- a/src/replication.c +++ b/src/replication.c @@ -3622,7 +3622,7 @@ void unblockClientWaitingReplicas(client *c) { updateStatsOnUnblock(c, 0, 0, 0); } -/* Check if there are clients blocked in WAIT, WAITAOF, or WAIT_PREREPL +/* Check if there are clients blocked in WAIT, WAITAOF, or WAIT_PREREPL * that can be unblocked since we received enough ACKs from replicas. */ void processClientsWaitingReplicas(void) { long long last_offset = 0; diff --git a/tests/unit/cluster/slot-migration.tcl b/tests/unit/cluster/slot-migration.tcl index 228bf1f96b..be8c51a0f7 100644 --- a/tests/unit/cluster/slot-migration.tcl +++ b/tests/unit/cluster/slot-migration.tcl @@ -346,16 +346,16 @@ start_cluster 3 3 {tags {external:skip cluster} overrides {cluster-allow-replica test "CLUSTER SETSLOT with an explicit timeout" { # Simulate a replica crash - catch {R 3 DEBUG RESTART} e + catch {R 3 DEBUG SEGFAULT} e # Setslot with an explicit 1ms timeoout set startTime [clock milliseconds] - catch {R 0 CLUSTER SETSLOT 609 MIGRATING $R1_id TIMEOUT 1} e + catch {R 0 CLUSTER SETSLOT 609 MIGRATING $R1_id TIMEOUT 3000} e set endTime [clock milliseconds] set duration [expr {$endTime - $startTime}] - # Assert that the execution time is much less than the default 2s timeout - assert {$duration < 50} + # Assert that the execution time is greater than the default 2s timeout + assert {$duration > 2000} # Setslot should fail with not enough good replicas to write after the timeout assert_equal {NOREPLICAS Not enough good replicas to write.} $e