src: add self-assigment memcpy checks
Some checks failed
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Coverage Linux (without intl) / coverage-linux-without-intl (push) Has been cancelled
Coverage Linux / coverage-linux (push) Has been cancelled
Coverage Windows / coverage-windows (push) Has been cancelled

Fixes: https://github.com/nodejs/node/issues/56718
PR-URL: https://github.com/nodejs/node/pull/56986
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Burkov Egor 2025-02-12 16:13:02 +03:00 committed by GitHub
parent 9ce1fffcdc
commit 85f5a6cc1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
}