]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Avoid UB when copying AnyP::Uri (#1604)
authorAlex <bigalex934@gmail.com>
Wed, 29 Nov 2023 20:29:36 +0000 (20:29 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 4 Dec 2023 09:24:07 +0000 (09:24 +0000)
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.

src/anyp/Uri.h

index ddf471243009fa62b8b0003fe4ee048e50e15bc3..a90a3b7d4710b2eeb776ac32de3758b3dfcc5885 100644 (file)
@@ -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;