diff options
| author | Konstantin Shegunov <kshegunov@gmail.com> | 2019-04-03 13:00:01 +0300 |
|---|---|---|
| committer | Konstantin Shegunov <kshegunov@gmail.com> | 2019-04-18 08:38:29 +0000 |
| commit | 642ef0c7311e18b9b4414af6ec3a2d8210bb6880 (patch) | |
| tree | 47626db671f50d3441fdbf9e2a629b6bab30b473 /src/network/ssl/qsslkey_p.cpp | |
| parent | 65314b6ce88cdbb28a22be0cab9856ec9bc9604b (diff) | |
Clear SSL key data as soon as possible when move-assigning
Move-assign uses qSwap to exchange the private pointer and thus can
extend the lifetime of sensitive data. The move assignment operator
is changed so it releases the private data as soon as possible.
[ChangeLog][QtNetwork][QSslKey] Key data is cleared as soon as
possible when move-assigning.
Change-Id: Iebd029bf657acfe000417ce648e3b3829948c0e5
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Diffstat (limited to 'src/network/ssl/qsslkey_p.cpp')
| -rw-r--r-- | src/network/ssl/qsslkey_p.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/network/ssl/qsslkey_p.cpp b/src/network/ssl/qsslkey_p.cpp index b29b38beab1..7d14aacebf9 100644 --- a/src/network/ssl/qsslkey_p.cpp +++ b/src/network/ssl/qsslkey_p.cpp @@ -385,6 +385,24 @@ QSslKey::QSslKey(const QSslKey &other) : d(other.d) { } +QSslKey::QSslKey(QSslKey &&other) noexcept + : d(nullptr) +{ + qSwap(d, other.d); +} + +QSslKey &QSslKey::operator=(QSslKey &&other) noexcept +{ + if (this == &other) + return *this; + + // If no one else is referencing the key data we want to make sure + // before we swap the d-ptr that it is not left in memory. + d.reset(); + qSwap(d, other.d); + return *this; +} + /*! Destroys the QSslKey object. */ |
