mirror of
https://github.com/redis/redis.git
synced 2026-02-18 18:20:31 -05:00
Fix minor inconsistency in connFormatAddr size argument (#14731)
Some checks are pending
CI / test-ubuntu-latest (push) Waiting to run
CI / test-sanitizer-address (push) Waiting to run
CI / build-debian-old (push) Waiting to run
CI / build-macos-latest (push) Waiting to run
CI / build-32bit (push) Waiting to run
CI / build-libc-malloc (push) Waiting to run
CI / build-centos-jemalloc (push) Waiting to run
CI / build-old-chain-jemalloc (push) Waiting to run
Codecov / code-coverage (push) Waiting to run
External Server Tests / test-external-standalone (push) Waiting to run
External Server Tests / test-external-cluster (push) Waiting to run
External Server Tests / test-external-nodebug (push) Waiting to run
Spellcheck / Spellcheck (push) Waiting to run
Some checks are pending
CI / test-ubuntu-latest (push) Waiting to run
CI / test-sanitizer-address (push) Waiting to run
CI / build-debian-old (push) Waiting to run
CI / build-macos-latest (push) Waiting to run
CI / build-32bit (push) Waiting to run
CI / build-libc-malloc (push) Waiting to run
CI / build-centos-jemalloc (push) Waiting to run
CI / build-old-chain-jemalloc (push) Waiting to run
Codecov / code-coverage (push) Waiting to run
External Server Tests / test-external-standalone (push) Waiting to run
External Server Tests / test-external-cluster (push) Waiting to run
External Server Tests / test-external-nodebug (push) Waiting to run
Spellcheck / Spellcheck (push) Waiting to run
**Type**: Refactoring / Code Cleanup **Description**: While reviewing the connection layer logic, I noticed a minor inconsistency in how buffer sizes are passed to `connFormatAddr`. In the error handling block of `acceptCommonHandler`, `sizeof(addr)` is currently used for both the remote address and the local address buffers. While both addr and laddr are defined with the same size (`NET_ADDR_STR_LEN`), it is more idiomatic and safer to use the sizeof of the actual buffer being populated. **This change ensures:** - Defensive Programming: Prevents potential buffer overflows or truncation issues if the array sizes are changed independently in the future. - Code Clarity: Removes ambiguity for future maintainers and ensures the logic is self-consistent.
This commit is contained in:
parent
3cc7e9956f
commit
a9838e6a4b
1 changed files with 2 additions and 2 deletions
|
|
@ -1599,7 +1599,7 @@ void acceptCommonHandler(connection *conn, int flags, char *ip) {
|
|||
char addr[NET_ADDR_STR_LEN] = {0};
|
||||
char laddr[NET_ADDR_STR_LEN] = {0};
|
||||
connFormatAddr(conn, addr, sizeof(addr), 1);
|
||||
connFormatAddr(conn, laddr, sizeof(addr), 0);
|
||||
connFormatAddr(conn, laddr, sizeof(laddr), 0);
|
||||
serverLog(LL_VERBOSE,
|
||||
"Accepted client connection in error state: %s (addr=%s laddr=%s)",
|
||||
connGetLastError(conn), addr, laddr);
|
||||
|
|
@ -1638,7 +1638,7 @@ void acceptCommonHandler(connection *conn, int flags, char *ip) {
|
|||
char addr[NET_ADDR_STR_LEN] = {0};
|
||||
char laddr[NET_ADDR_STR_LEN] = {0};
|
||||
connFormatAddr(conn, addr, sizeof(addr), 1);
|
||||
connFormatAddr(conn, laddr, sizeof(addr), 0);
|
||||
connFormatAddr(conn, laddr, sizeof(laddr), 0);
|
||||
serverLog(LL_WARNING,
|
||||
"Error registering fd event for the new client connection: %s (addr=%s laddr=%s)",
|
||||
connGetLastError(conn), addr, laddr);
|
||||
|
|
|
|||
Loading…
Reference in a new issue