From: Alex Date: Wed, 29 Nov 2023 20:29:36 +0000 (+0000) Subject: Avoid UB when copying AnyP::Uri (#1604) X-Git-Tag: SQUID_7_0_1~269 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eb29c4f004336fbc7afa8c15b65f927480f0795b;p=thirdparty%2Fsquid.git Avoid UB when copying AnyP::Uri (#1604) Without a self-assignment check, a memcpy(3) call in Uri copy assignment operator could result in undefined behavior. Let the compiler generate all this code instead. --- diff --git a/src/anyp/Uri.h b/src/anyp/Uri.h index ddf4712430..a90a3b7d47 100644 --- a/src/anyp/Uri.h +++ b/src/anyp/Uri.h @@ -34,20 +34,10 @@ class Uri public: Uri(): hostIsNumeric_(false) { *host_ = 0; } Uri(AnyP::UriScheme const &aScheme); - Uri(const Uri &other) { - this->operator =(other); - } - Uri &operator =(const Uri &o) { - scheme_ = o.scheme_; - userInfo_ = o.userInfo_; - memcpy(host_, o.host_, sizeof(host_)); - hostIsNumeric_ = o.hostIsNumeric_; - hostAddr_ = o.hostAddr_; - port_ = o.port_; - path_ = o.path_; - touch(); - return *this; - } + Uri(const Uri &) = default; + Uri(Uri &&) = default; + Uri &operator =(const Uri &) = default; + Uri &operator =(Uri &&) = default; void clear() { scheme_=AnyP::PROTO_NONE;