You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by tw...@apache.org on 2023/04/12 06:08:57 UTC

[incubator-kvrocks] branch unstable updated: Fix disordered stack pop in replyToRedisReply (#1380)

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

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


The following commit(s) were added to refs/heads/unstable by this push:
     new db5d91de Fix disordered stack pop in replyToRedisReply (#1380)
db5d91de is described below

commit db5d91defc5d7ecc56899505e6e295baa64fd14e
Author: Twice <tw...@gmail.com>
AuthorDate: Wed Apr 12 14:08:52 2023 +0800

    Fix disordered stack pop in replyToRedisReply (#1380)
---
 src/storage/scripting.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/storage/scripting.cc b/src/storage/scripting.cc
index 20f7e2e9..1f5c263a 100644
--- a/src/storage/scripting.cc
+++ b/src/storage/scripting.cc
@@ -261,7 +261,7 @@ Status evalGenericCommand(Redis::Connection *conn, const std::string &body_or_sh
     lua_pop(lua, 2);
   } else {
     *output = replyToRedisReply(lua);
-    lua_pop(lua, 1);
+    lua_pop(lua, 2);
   }
 
   // clean global variables to prevent information leak in function commands
@@ -688,6 +688,7 @@ void pushError(lua_State *lua, const char *err) {
   lua_settable(lua, -3);
 }
 
+// this function does not pop any element on the stack
 std::string replyToRedisReply(lua_State *lua) {
   std::string output;
   const char *obj_s = nullptr;
@@ -717,7 +718,7 @@ std::string replyToRedisReply(lua_State *lua) {
       t = lua_type(lua, -1);
       if (t == LUA_TSTRING) {
         output = Redis::Error(lua_tostring(lua, -1));
-        lua_pop(lua, 2);
+        lua_pop(lua, 1);
         return output;
       }
       lua_pop(lua, 1); /* Discard field name pushed before. */
@@ -743,6 +744,7 @@ std::string replyToRedisReply(lua_State *lua) {
           }
           mbulklen++;
           output += replyToRedisReply(lua);
+          lua_pop(lua, 1);
         }
         output = Redis::MultiLen(mbulklen) + output;
       }
@@ -750,7 +752,6 @@ std::string replyToRedisReply(lua_State *lua) {
     default:
       output = Redis::NilString();
   }
-  lua_pop(lua, 1);
   return output;
 }