Commit ad7081f8 authored by zhujiashun's avatar zhujiashun

redis_server_protocol: refine code

parent c7ba8c54
...@@ -107,8 +107,7 @@ int ConsumeCommand(RedisConnContext* ctx, ...@@ -107,8 +107,7 @@ int ConsumeCommand(RedisConnContext* ctx,
result = ch->Run(commands, &output, is_last); result = ch->Run(commands, &output, is_last);
if (result == RedisCommandHandler::CONTINUE) { if (result == RedisCommandHandler::CONTINUE) {
if (ctx->batched_size != 0) { if (ctx->batched_size != 0) {
LOG(ERROR) << "Do you forget to return OK " LOG(ERROR) << "Do you forget to return OK when is_last is true?";
"when is_last is true?";
return -1; return -1;
} }
ctx->transaction_handler.reset(ch->NewTransactionHandler()); ctx->transaction_handler.reset(ch->NewTransactionHandler());
...@@ -185,11 +184,10 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket, ...@@ -185,11 +184,10 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket,
if (err != PARSE_OK) { if (err != PARSE_OK) {
break; break;
} }
std::string next_command_name; // next_commands must have at least one element, otherwise parse.Consume()
if (!next_commands.empty()) { // should return error.
next_command_name = next_commands[0]; if (ConsumeCommand(ctx, current_commands, next_commands[0], &arena,
} false, &sendbuf) != 0) {
if (ConsumeCommand(ctx, current_commands, next_command_name, &arena, false, &sendbuf) != 0) {
return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG); return MakeParseError(PARSE_ERROR_ABSOLUTELY_WRONG);
} }
current_commands.swap(next_commands); current_commands.swap(next_commands);
......
...@@ -377,6 +377,10 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf, ...@@ -377,6 +377,10 @@ ParseError RedisCommandParser::Consume(butil::IOBuf& buf,
LOG(ERROR) << '`' << intbuf + 1 << "' is not a valid 64-bit decimal"; LOG(ERROR) << '`' << intbuf + 1 << "' is not a valid 64-bit decimal";
return PARSE_ERROR_ABSOLUTELY_WRONG; return PARSE_ERROR_ABSOLUTELY_WRONG;
} }
if (value <= 0) {
LOG(ERROR) << "Invalid len=" << value << " in redis command";
return PARSE_ERROR_ABSOLUTELY_WRONG;
}
if (!_parsing_array) { if (!_parsing_array) {
buf.pop_front(crlf_pos + 2/*CRLF*/); buf.pop_front(crlf_pos + 2/*CRLF*/);
_parsing_array = true; _parsing_array = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment