ulidtko commented on a change in pull request #2234:
URL: https://github.com/apache/thrift/pull/2234#discussion_r485661899
##########
File path: lib/cpp/src/thrift/transport/TSocket.cpp
##########
@@ -329,31 +329,27 @@ void TSocket::openConnection(struct addrinfo* res) {
if (!path_.empty()) {
#ifndef _WIN32
- size_t len = path_.size() + 1;
- if (len > sizeof(((sockaddr_un*)nullptr)->sun_path)) {
+ if ((path_.size() + 1) > sizeof(((sockaddr_un*)nullptr)->sun_path)) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TSocket::open() Unix Domain socket path too long",
errno_copy);
throw TTransportException(TTransportException::NOT_OPEN, " Unix Domain
socket path too long");
}
struct sockaddr_un address;
+ // Store the zero-terminated path in address.sun_path
+ memset(&address, '\0', sizeof(address));
address.sun_family = AF_UNIX;
- memcpy(address.sun_path, path_.c_str(), len);
-
- auto structlen = static_cast<socklen_t>(sizeof(address));
+ memcpy(address.sun_path, path_.c_str(), path_.size());
if (!address.sun_path[0]) { // abstract namespace socket
-#ifdef __linux__
- // sun_path is not null-terminated in this case and structlen determines
its length
- structlen -= sizeof(address.sun_path) - len;
-#else
Review comment:
I think I get it.
This code would "truncate" the unused bytes from `address.sun_path` (which'd
include the null terminator BTW).
This may have worked — but `unix(7)` clearly says to pass `sizeof(struct
sockaddr_un)`, the full thing, without any truncation business.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]