You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by ti...@apache.org on 2022/06/24 10:52:30 UTC
[incubator-kvrocks] branch unstable updated: Fix Wrongly parsed the RESP empty/null array (#652)
This is an automated email from the ASF dual-hosted git repository.
tison 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 e910200 Fix Wrongly parsed the RESP empty/null array (#652)
e910200 is described below
commit e910200dd43427a1b2d1fa4f31a6975734a069b2
Author: willshS <41...@users.noreply.github.com>
AuthorDate: Fri Jun 24 18:52:25 2022 +0800
Fix Wrongly parsed the RESP empty/null array (#652)
---
src/redis_request.cc | 9 +++++++--
src/redis_request.h | 2 +-
tests/tcl/tests/unit/protocol.tcl | 7 +++++++
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/redis_request.cc b/src/redis_request.cc
index 66a82bb..1fdd5e9 100644
--- a/src/redis_request.cc
+++ b/src/redis_request.cc
@@ -59,12 +59,17 @@ Status Request::Tokenize(evbuffer *input) {
svr_->stats_.IncrInbondBytes(len);
if (line[0] == '*') {
try {
- multi_bulk_len_ = std::stoull(std::string(line + 1, len-1));
+ multi_bulk_len_ = std::stoll(std::string(line + 1, len-1));
} catch (std::exception &e) {
free(line);
return Status(Status::NotOK, "Protocol error: invalid multibulk length");
}
- if (multi_bulk_len_ > PROTO_MULTI_MAX_SIZE) {
+ if (multi_bulk_len_ <= 0) {
+ multi_bulk_len_ = 0;
+ free(line);
+ continue;
+ }
+ if (multi_bulk_len_ > (int64_t)PROTO_MULTI_MAX_SIZE) {
free(line);
return Status(Status::NotOK, "Protocol error: invalid multibulk length");
}
diff --git a/src/redis_request.h b/src/redis_request.h
index 35b1ea9..c7f3e1c 100644
--- a/src/redis_request.h
+++ b/src/redis_request.h
@@ -52,7 +52,7 @@ class Request {
enum ParserState { ArrayLen, BulkLen, BulkData };
ParserState state_ = ArrayLen;
- size_t multi_bulk_len_ = 0;
+ int64_t multi_bulk_len_ = 0;
size_t bulk_len_ = 0;
CommandTokens tokens_;
std::vector<CommandTokens> commands_;
diff --git a/tests/tcl/tests/unit/protocol.tcl b/tests/tcl/tests/unit/protocol.tcl
index a542741..c6ed5cc 100644
--- a/tests/tcl/tests/unit/protocol.tcl
+++ b/tests/tcl/tests/unit/protocol.tcl
@@ -75,6 +75,13 @@ start_server {tags {"protocol network"}} {
reconnect
assert_error "*wrong*arguments*" {r ping x y z}
}
+
+ test "Empty array parsed" {
+ reconnect
+ r write "*-1\r\n*3\r\n\$3\r\nset\r\n\$3\r\nkey\r\n\$3\r\nval\r\n"
+ r flush
+ assert_equal "OK" [r read]
+ }
}
start_server {tags {"regression"}} {