Copilot commented on code in PR #3566:
URL: https://github.com/apache/brpc/pull/3566#discussion_r4102168853
##########
src/brpc/redis_command.cpp:
##########
@@ -147,24 +153,38 @@ 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*);
+ // Callers pass const char* (c_str()/data()); read it back with
+ // the exact type to avoid UB at the variadic boundary.
+ arg = va_arg(ap, const char*);
Review Comment:
`AddCommand`'s public templates also accept mutable `char*` arguments (for
example, a `char value[]` decays to `char*`), but this `va_arg` now
unconditionally extracts `const char*`. Those types are not compatible at a
variadic boundary, so such existing callers still have undefined behavior
despite the comment claiming the exact type is being used. Normalize pointer
arguments before entering the `va_list` formatter or use a typed dispatch that
supports both `char*` and `const char*`.
--
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]