You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by hu...@apache.org on 2023/11/24 14:07:49 UTC

(kvrocks) branch unstable updated: Fix server crash when receiving the empty inline command (#1909)

This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new db4669a5 Fix server crash when receiving the empty inline command (#1909)
db4669a5 is described below

commit db4669a59c992935a3dd473da821b3f9b21edfb0
Author: hulk <hu...@gmail.com>
AuthorDate: Fri Nov 24 22:07:43 2023 +0800

    Fix server crash when receiving the empty inline command (#1909)
---
 src/server/redis_connection.cc              |  1 +
 src/server/redis_request.cc                 |  1 +
 tests/gocase/unit/protocol/protocol_test.go | 12 +++++++++++-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/server/redis_connection.cc b/src/server/redis_connection.cc
index a7dec01d..4d468983 100644
--- a/src/server/redis_connection.cc
+++ b/src/server/redis_connection.cc
@@ -307,6 +307,7 @@ void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {
   while (!to_process_cmds->empty()) {
     auto cmd_tokens = to_process_cmds->front();
     to_process_cmds->pop_front();
+    if (cmd_tokens.empty()) continue;
 
     bool is_multi_exec = IsFlagEnabled(Connection::kMultiExec);
     if (IsFlagEnabled(redis::Connection::kCloseAfterReply) && !is_multi_exec) break;
diff --git a/src/server/redis_request.cc b/src/server/redis_request.cc
index 9d82d00f..f6faa7b1 100644
--- a/src/server/redis_request.cc
+++ b/src/server/redis_request.cc
@@ -91,6 +91,7 @@ Status Request::Tokenize(evbuffer *input) {
           }
 
           tokens_ = util::Split(std::string(line.get(), line.length), " \t");
+          if (tokens_.empty()) continue;
           commands_.emplace_back(std::move(tokens_));
           state_ = ArrayLen;
         }
diff --git a/tests/gocase/unit/protocol/protocol_test.go b/tests/gocase/unit/protocol/protocol_test.go
index de210413..9ba40bec 100644
--- a/tests/gocase/unit/protocol/protocol_test.go
+++ b/tests/gocase/unit/protocol/protocol_test.go
@@ -31,14 +31,24 @@ func TestProtocolNetwork(t *testing.T) {
 	srv := util.StartServer(t, map[string]string{})
 	defer srv.Close()
 
-	t.Run("handle an empty array", func(t *testing.T) {
+	t.Run("empty bulk array command", func(t *testing.T) {
 		c := srv.NewTCPClient()
 		defer func() { require.NoError(t, c.Close()) }()
+		require.NoError(t, c.Write("*-1\r\n"))
+		require.NoError(t, c.Write("*0\r\n"))
 		require.NoError(t, c.Write("\r\n"))
 		require.NoError(t, c.Write("*1\r\n$4\r\nPING\r\n"))
 		c.MustRead(t, "+PONG")
 	})
 
+	t.Run("empty inline command", func(t *testing.T) {
+		c := srv.NewTCPClient()
+		defer func() { require.NoError(t, c.Close()) }()
+		require.NoError(t, c.Write(" \r\n"))
+		require.NoError(t, c.Write("*1\r\n$4\r\nPING\r\n"))
+		c.MustRead(t, "+PONG")
+	})
+
 	t.Run("out of range multibulk length", func(t *testing.T) {
 		c := srv.NewTCPClient()
 		defer func() { require.NoError(t, c.Close()) }()