chenBright commented on code in PR #3024:
URL: https://github.com/apache/brpc/pull/3024#discussion_r2206490549


##########
src/brpc/redis_command.cpp:
##########
@@ -370,16 +371,76 @@ size_t RedisCommandParser::ParsedArgsSize() {
     return _args.size();
 }
 
+int find_crlf(const char* pfc, size_t length) {
+    for (size_t i = 0; i < length - 1; ++i) {
+        if (pfc[i] == '\r' && pfc[i + 1] == '\n') {
+            return i;
+        }
+    }
+    return -1;
+}
+
 ParseError RedisCommandParser::Consume(butil::IOBuf& buf,
                                        std::vector<butil::StringPiece>* args,
                                        butil::Arena* arena) {
-    const char* pfc = (const char*)buf.fetch1();
+    const auto pfc = static_cast<const char *>(buf.fetch1());
     if (pfc == NULL) {
         return PARSE_ERROR_NOT_ENOUGH_DATA;
     }
     // '*' stands for array "*<size>\r\n<sub-reply1><sub-reply2>..."
     if (!_parsing_array && *pfc != '*') {
-        return PARSE_ERROR_TRY_OTHERS;
+        if (!std::isalpha(static_cast<unsigned char>(*pfc))) {
+            return PARSE_ERROR_TRY_OTHERS;
+        }
+        const size_t buf_size = buf.size();
+        const auto copy_str = static_cast<char *>(arena->allocate(buf_size));
+        buf.copy_to(copy_str, buf_size);
+        if (*copy_str == ' ') {
+            return PARSE_ERROR_ABSOLUTELY_WRONG;
+        }
+        const int crlf_pos = find_crlf(copy_str, buf_size);

Review Comment:
   Use `butil::StringPiece::find` instead of `find_crlf`, like
   `const size_t crlf_pos = butil::StringPiece(intbuf, ncopied).find("\r\n");`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to