two-headBoy commented on code in PR #3566:
URL: https://github.com/apache/brpc/pull/3566#discussion_r4106110031


##########
src/brpc/redis_command.cpp:
##########
@@ -147,24 +153,40 @@ RedisCommandFormatV(butil::IOBuf* outbuf, const char* 
fmt, va_list ap) {
                 compbuf.push_back(*c);
             }
         } else {
-            char *arg;
+            const char* arg;
             size_t size;
 
             switch(c[1]) {
             case 's':
-                arg = va_arg(ap, char*);
+                // Most callers pass const char* (c_str()/data()); reading as
+                // const char* matches them exactly. char* is ABI-identical to
+                // const char*, so mutable callers stay correct in practice; a
+                // single va_arg cannot serve both types exactly.
+                arg = va_arg(ap, const char*);
+                // strlen(NULL) is UB; forbid it explicitly instead of 
crashing.
+                if (arg == nullptr) {
+                    return butil::Status(EINVAL, "%%s argument is NULL");

Review Comment:
   I chose the second option you described: drop the stray CHECK so callers get
   false/has_error() as the header documents, rather than treating these errors
   as fatal-by-design. Please check.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to