fix: Segmentation fault after telnet and return#3097
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a segmentation fault encountered after telnet operations by adding additional checks and handling for empty command inputs.
- Added early returns and conditional checks to prevent accessing empty command elements.
- Refactored parts of the command execution flow to differentiate between empty and valid commands.
- Adjusted redis parser behavior to consistently enqueue command buffers.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/pika_client_conn.cc | Added validation for empty command arguments and refactored command execution logic to separately process empty and valid commands. |
| src/net/src/redis_parser.cc | Modified the parser to always push commands (even empty ones) and conditionally process them with DealMessage. |
Comments suppressed due to low confidence (1)
src/net/src/redis_parser.cc:370
- [nitpick] Add a comment clarifying that empty commands are intentionally pushed into argvs_ to maintain consistent behavior throughout the parsing process. This will help future maintainers understand the design decision.
argvs_.push_back(argv_);
| std::vector<bool> is_empty_cmd(argvs.size()); | ||
| std::vector<net::RedisCmdArgsType> valid_argvs; | ||
|
|
||
| for (size_t i = 0; i < argvs.size(); ++i) { | ||
| if (argvs[i].empty()) { | ||
| is_empty_cmd[i] = true; | ||
| } else { | ||
| is_empty_cmd[i] = false; | ||
| valid_argvs.push_back(argvs[i]); | ||
| } | ||
| } | ||
|
|
||
| resp_num.store(static_cast<int32_t>(argvs.size())); | ||
| for (const auto& argv : argvs) { | ||
|
|
||
| // Process empty commands with empty response | ||
| for (size_t i = 0; i < argvs.size(); ++i) { | ||
| std::shared_ptr<std::string> resp_ptr = std::make_shared<std::string>(); | ||
| if (is_empty_cmd[i]) { | ||
| // For empty commands, return empty response to keep connection alive | ||
| *resp_ptr = "\r\n"; | ||
| } | ||
| resp_array.push_back(resp_ptr); | ||
| ExecRedisCmd(argv, resp_ptr, cache_miss_in_rtc); | ||
| } | ||
|
|
There was a problem hiding this comment.
[nitpick] Consider combining the loop that filters empty commands and constructs valid_argvs with the loop that initializes resp_array. Merging these loops may simplify the code and reduce the number of iterations without compromising clarity.
fix: #3095