mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2024-12-14 11:58:02 +00:00
fix(rename-command): Fix subtle UB when renaming commands (#2132)
In practive, commands larger than SSO would not work. Fixes #2131
This commit is contained in:
parent
ac457a64e4
commit
053a33d24d
2 changed files with 16 additions and 11 deletions
|
@ -117,7 +117,7 @@ void CommandRegistry::Init(unsigned int thread_count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandRegistry& CommandRegistry::operator<<(CommandId cmd) {
|
CommandRegistry& CommandRegistry::operator<<(CommandId cmd) {
|
||||||
auto k = cmd.name();
|
string k = string(cmd.name());
|
||||||
|
|
||||||
absl::InlinedVector<std::string_view, 2> maybe_subcommand = StrSplit(cmd.name(), " ");
|
absl::InlinedVector<std::string_view, 2> maybe_subcommand = StrSplit(cmd.name(), " ");
|
||||||
const bool is_sub_command = maybe_subcommand.size() == 2;
|
const bool is_sub_command = maybe_subcommand.size() == 2;
|
||||||
|
|
|
@ -99,8 +99,9 @@ class DflyRenameCommandTest : public DflyEngineTest {
|
||||||
protected:
|
protected:
|
||||||
DflyRenameCommandTest() : DflyEngineTest() {
|
DflyRenameCommandTest() : DflyEngineTest() {
|
||||||
// rename flushall to myflushall, flushdb command will not be able to execute
|
// rename flushall to myflushall, flushdb command will not be able to execute
|
||||||
absl::SetFlag(&FLAGS_rename_command,
|
absl::SetFlag(
|
||||||
std::vector<std::string>({"flushall=myflushall", "flushdb="}));
|
&FLAGS_rename_command,
|
||||||
|
std::vector<std::string>({"flushall=myflushall", "flushdb=", "ping=abcdefghijklmnop"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown() {
|
void TearDown() {
|
||||||
|
@ -113,16 +114,20 @@ TEST_F(DflyRenameCommandTest, RenameCommand) {
|
||||||
Run({"set", "a", "1"});
|
Run({"set", "a", "1"});
|
||||||
ASSERT_EQ(1, CheckedInt({"dbsize"}));
|
ASSERT_EQ(1, CheckedInt({"dbsize"}));
|
||||||
// flushall should not execute anything and should return error, as it was renamed.
|
// flushall should not execute anything and should return error, as it was renamed.
|
||||||
RespExpr resp = Run({"flushall"});
|
ASSERT_THAT(Run({"flushall"}), ErrArg("unknown command `FLUSHALL`"));
|
||||||
ASSERT_THAT(resp, ErrArg("unknown command `FLUSHALL`"));
|
|
||||||
ASSERT_EQ(1, CheckedInt({"dbsize"}));
|
ASSERT_EQ(1, CheckedInt({"dbsize"}));
|
||||||
resp = Run({"myflushall"});
|
|
||||||
ASSERT_EQ(resp, "OK");
|
ASSERT_EQ(Run({"myflushall"}), "OK");
|
||||||
|
|
||||||
ASSERT_EQ(0, CheckedInt({"dbsize"}));
|
ASSERT_EQ(0, CheckedInt({"dbsize"}));
|
||||||
resp = Run({"flushdb", "0"});
|
|
||||||
ASSERT_THAT(resp, ErrArg("unknown command `FLUSHDB`"));
|
ASSERT_THAT(Run({"flushdb", "0"}), ErrArg("unknown command `FLUSHDB`"));
|
||||||
resp = Run({""});
|
|
||||||
ASSERT_THAT(resp, ErrArg("unknown command ``"));
|
ASSERT_THAT(Run({""}), ErrArg("unknown command ``"));
|
||||||
|
|
||||||
|
ASSERT_THAT(Run({"ping"}), ErrArg("unknown command `PING`"));
|
||||||
|
ASSERT_THAT(Run({"abcdefghijklmnop"}), "PONG");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SingleThreadDflyEngineTest, GlobalSingleThread) {
|
TEST_F(SingleThreadDflyEngineTest, GlobalSingleThread) {
|
||||||
|
|
Loading…
Reference in a new issue