This is an automated email from the ASF dual-hosted git repository.
PragmaTwice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new f912eef4e fix(common): use correct buffer size for IPv6 in inet_ntop
(#3662)
f912eef4e is described below
commit f912eef4e1dd4a6447c8b9410ae314cb0e2af553
Author: weimeng <[email protected]>
AuthorDate: Mon Oct 12 15:52:56 2026 +0800
fix(common): use correct buffer size for IPv6 in inet_ntop (#3662)
## Summary
Fix a bug in `GetPeerAddr` where the IPv6 branch passed
`INET_ADDRSTRLEN` (16)
instead of `INET6_ADDRSTRLEN` (46) as the buffer size to `inet_ntop`,
causing
IPv6 address strings to be silently truncated.
## Root Cause
In `src/common/io_util.cc`, `GetPeerAddr` declares a correctly sized
buffer
`char buf[INET6_ADDRSTRLEN]` (46 bytes) for the IPv6 case, but then
passes
`INET_ADDRSTRLEN` (16 bytes) to `inet_ntop`:
```cpp
inet_ntop(AF_INET6, ..., buf, INET_ADDRSTRLEN); // 16, should be 46
Co-authored-by: weimeng <[email protected]>
---
src/common/io_util.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/common/io_util.cc b/src/common/io_util.cc
index e481b1803..51c109357 100644
--- a/src/common/io_util.cc
+++ b/src/common/io_util.cc
@@ -335,7 +335,7 @@ StatusOr<std::tuple<std::string, uint32_t>> GetPeerAddr(int
fd) {
if (sa.ss_family == AF_INET6) {
char buf[INET6_ADDRSTRLEN];
auto sa6 = reinterpret_cast<sockaddr_in6 *>(&sa);
- inet_ntop(AF_INET6, reinterpret_cast<void *>(&sa6->sin6_addr), buf,
INET_ADDRSTRLEN);
+ inet_ntop(AF_INET6, reinterpret_cast<void *>(&sa6->sin6_addr), buf,
INET6_ADDRSTRLEN);
return {buf, ntohs(sa6->sin6_port)};
} else if (sa.ss_family == AF_INET) {
auto sa4 = reinterpret_cast<sockaddr_in *>(&sa);