This is an automated email from the ASF dual-hosted git repository. moonchen pushed a commit to branch uds-listen-path-length in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit b42ce06f5978b055a213fa42089cc379df14ba1f Author: Mo Chen <[email protected]> AuthorDate: Mon Jul 13 18:36:11 2026 -0500 UnAddr: zero-initialize _path and guard null-pointer construction assign(sockaddr const *) leaves _path untouched on a null address, so a constructor that forwards a null pointer left the buffer uninitialized; a later copy then scanned uninitialized bytes. Give _path a default member initializer so every construction yields a valid empty string, and guard the IpEndpoint const * constructor against a null pointer. --- include/tscore/ink_inet.h | 13 ++++++++++--- src/tscore/unit_tests/test_ink_inet.cc | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/tscore/ink_inet.h b/include/tscore/ink_inet.h index ac31f15b12..a39e1da133 100644 --- a/include/tscore/ink_inet.h +++ b/include/tscore/ink_inet.h @@ -1609,7 +1609,7 @@ IpAddr::hash() const struct UnAddr { using self = UnAddr; - UnAddr() { _path[0] = 0; } + UnAddr() = default; UnAddr(self const &addr) { ink_strlcpy(_path, addr._path, TS_UNIX_SIZE); } explicit UnAddr(const char *path) { ink_strlcpy(_path, path, TS_UNIX_SIZE); } @@ -1620,7 +1620,12 @@ struct UnAddr { /// Construct from @c IpEndpoint. explicit UnAddr(IpEndpoint const &addr) { this->assign(&addr.sa); } /// Construct from @c IpEndpoint. - explicit UnAddr(IpEndpoint const *addr) { this->assign(&addr->sa); } + explicit UnAddr(IpEndpoint const *addr) + { + if (addr) { + this->assign(&addr->sa); + } + } /// Assign sockaddr storage. self &assign(sockaddr const *addr); @@ -1645,7 +1650,9 @@ struct UnAddr { return *this; } - char _path[TS_UNIX_SIZE]; + // Default-initialized so a constructor whose assign() gets a null address (which leaves + // the buffer untouched) still yields a valid empty C string instead of uninitialized bytes. + char _path[TS_UNIX_SIZE]{}; }; inline UnAddr & diff --git a/src/tscore/unit_tests/test_ink_inet.cc b/src/tscore/unit_tests/test_ink_inet.cc index 034012e946..0dd2304b10 100644 --- a/src/tscore/unit_tests/test_ink_inet.cc +++ b/src/tscore/unit_tests/test_ink_inet.cc @@ -303,4 +303,13 @@ TEST_CASE("ink_inet_unix", "[libts][inet][unix]") UnAddr assigned; assigned = from_sockaddr; REQUIRE(assigned._path[TS_UNIX_SIZE - 1] == '\0'); + + // Constructing from a null address must leave _path an empty, terminated string so the copy + // paths don't read uninitialized memory. + UnAddr from_null_sa{static_cast<sockaddr const *>(nullptr)}; + REQUIRE(from_null_sa._path[0] == '\0'); + UnAddr from_null_ep{static_cast<IpEndpoint const *>(nullptr)}; + REQUIRE(from_null_ep._path[0] == '\0'); + UnAddr copied_null(from_null_sa); + REQUIRE(copied_null._path[0] == '\0'); }
