Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions groups/nts/ntsu/ntsu_socketutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,27 +937,48 @@ ntsa::Error SocketUtil::Impl::convert(ntsa::Endpoint* endpoint,
const bsl::size_t pathOffset =
offsetof(struct sockaddr_un, sun_path);

if (socketAddressSize == pathOffset) {
const bsl::size_t addressSize =
static_cast<bsl::size_t>(socketAddressSize);

if (addressSize <= pathOffset) {
localName->setUnnamed();
}
else {
// The address length reported by the socket API is the
// authoritative extent of 'sun_path': the field is not
// guaranteed to be null-terminated (abstract names never are,
// and a peer may supply a truncated or unterminated path).
// Bound the scan by that length, clamped to the capacity of
// the field itself, so the scan never reads bytes outside the
// address.

bsl::size_t pathSize = addressSize - pathOffset;
if (pathSize > sizeof(socketAddressLocal->sun_path)) {
pathSize = sizeof(socketAddressLocal->sun_path);
}

const char* begin = socketAddressLocal->sun_path;
const char* limit = begin + pathSize;

if (*begin == 0) {
localName->setAbstract();
++begin;
}

const char* end = begin;
while (*end != 0) {
while (end != limit && *end != 0) {
++end;
}

if (begin == end) {
localName->setUnnamed();
}
else {
localName->setValue(bslstl::StringRef(begin, end));
ntsa::Error error =
localName->setValue(bslstl::StringRef(begin, end));
if (error) {
return error;
}
}
}
}
Expand Down
Loading