Skip to content

Commit

Permalink
src: add self-assigment memcpy checks
Browse files Browse the repository at this point in the history
Fixes: #56718
PR-URL: #56986
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
wooffie authored Feb 12, 2025
1 parent 9ce1fff commit 85f5a6c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/node_sockaddr-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ SocketAddress::SocketAddress(const SocketAddress& addr) {
}

SocketAddress& SocketAddress::operator=(const sockaddr* addr) {
memcpy(&address_, addr, GetLength(addr));
if (reinterpret_cast<const sockaddr*>(&address_) != addr) {
memcpy(&address_, addr, GetLength(addr));
}
return *this;
}

SocketAddress& SocketAddress::operator=(const SocketAddress& addr) {
memcpy(&address_, &addr.address_, addr.length());
if (this != &addr) {
memcpy(&address_, &addr.address_, addr.length());
}
return *this;
}

Expand Down

0 comments on commit 85f5a6c

Please sign in to comment.