From b3e5c93f4ba1c281f382290888ebcd7541133af2 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 4 Sep 2018 15:49:48 +0200 Subject: [PATCH] Add explicit constructors/operators to sanitizing_blob_(z)f Otherwise the compiler might generate default ones - and delete them too. --- lib/EAPBase/include/EAP.h | 109 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 3 deletions(-) diff --git a/lib/EAPBase/include/EAP.h b/lib/EAPBase/include/EAP.h index 043690b..0c6cbcf 100644 --- a/lib/EAPBase/include/EAP.h +++ b/lib/EAPBase/include/EAP.h @@ -672,6 +672,16 @@ namespace eap memcpy(data, other.data, N); } + /// + /// Moves the BLOB + /// + /// \param[inout] other BLOB to move from + /// + inline sanitizing_blob_f(_Inout_ sanitizing_blob_f &&other) + { + memcpy(data, other.data, N); + } + /// /// Moves the BLOB /// @@ -708,7 +718,21 @@ namespace eap /// /// Moves the BLOB /// - /// \param[inout] other Zero-initialized BLOB to copy from + /// \param[inout] other BLOB to move from + /// + /// \returns Reference to this object + /// + inline sanitizing_blob_f& operator=(_Inout_ sanitizing_blob_f &&other) + { + if (this != std::addressof(other)) + memcpy(data, other.data, N); + return *this; + } + + /// + /// Moves the BLOB + /// + /// \param[inout] other Zero-initialized BLOB to move from /// /// \returns Reference to this object /// @@ -791,9 +815,9 @@ namespace eap /// /// Copies a BLOB /// - /// \param[in] other BLOB to copy from + /// \param[in] other Zero-initialized BLOB to copy from /// - inline sanitizing_blob_zf(_In_ const sanitizing_blob_f &other) : + inline sanitizing_blob_zf(_In_ const sanitizing_blob_zf &other) : sanitizing_blob_f(other) { } @@ -806,6 +830,85 @@ namespace eap inline sanitizing_blob_zf(_Inout_ sanitizing_blob_zf &&other) : sanitizing_blob_f(std::move(other)) { + memset(other.data, 0, N); + } + + /// + /// Copies a BLOB + /// + /// \param[in] other BLOB to copy from + /// + inline sanitizing_blob_zf(_In_ const sanitizing_blob_f &other) : + sanitizing_blob_f(other) + { + } + + /// + /// Moves the BLOB + /// + /// \param[inout] other BLOB to move from + /// + inline sanitizing_blob_zf(_Inout_ sanitizing_blob_f &&other) : + sanitizing_blob_f(std::move(other)) + { + } + + /// + /// Copies a BLOB + /// + /// \param[in] other Zero-initialized BLOB to copy from + /// + /// \returns Reference to this object + /// + inline sanitizing_blob_zf& operator=(_In_ const sanitizing_blob_zf &other) + { + if (this != std::addressof(other)) + memcpy(data, other.data, N); + return *this; + } + + /// + /// Moves the BLOB + /// + /// \param[inout] other Zero-initialized BLOB to move from + /// + /// \returns Reference to this object + /// + inline sanitizing_blob_zf& operator=(_Inout_ sanitizing_blob_zf &&other) + { + if (this != std::addressof(other)) { + memcpy(data, other.data, N); + memset(other.data, 0, N); + } + return *this; + } + + /// + /// Copies a BLOB + /// + /// \param[in] other BLOB to copy from + /// + /// \returns Reference to this object + /// + inline sanitizing_blob_zf& operator=(_In_ const sanitizing_blob_f &other) + { + if (this != std::addressof(other)) + memcpy(data, other.data, N); + return *this; + } + + /// + /// Moves the BLOB + /// + /// \param[inout] other BLOB to move from + /// + /// \returns Reference to this object + /// + inline sanitizing_blob_zf& operator=(_Inout_ sanitizing_blob_f &&other) + { + if (this != std::addressof(other)) + memcpy(data, other.data, N); + return *this; } }; #pragma pack(pop)