From 8e3c9410dcf51fcf1ee75401f1a3f797c8fdf7c9 Mon Sep 17 00:00:00 2001 From: brain5lug Date: Fri, 29 Sep 2017 00:48:14 +0300 Subject: [PATCH 1/2] missed self assigment check for EDDSAPoint --- libi2pd/Signature.h | 46 ++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/libi2pd/Signature.h b/libi2pd/Signature.h index b85ef4cf..531fdfdf 100644 --- a/libi2pd/Signature.h +++ b/libi2pd/Signature.h @@ -363,31 +363,43 @@ namespace crypto // EdDSA struct EDDSAPoint { - BIGNUM * x, * y; - BIGNUM * z, * t; // projective coordinates - EDDSAPoint (): x(nullptr), y(nullptr), z(nullptr), t(nullptr) {}; - EDDSAPoint (const EDDSAPoint& other): x(nullptr), y(nullptr), z(nullptr), t(nullptr) - { *this = other; }; - EDDSAPoint (EDDSAPoint&& other): x(nullptr), y(nullptr), z(nullptr), t(nullptr) - { *this = std::move (other); }; - EDDSAPoint (BIGNUM * x1, BIGNUM * y1, BIGNUM * z1 = nullptr, BIGNUM * t1 = nullptr): x(x1), y(y1), z(z1), t(t1) {}; - ~EDDSAPoint () { BN_free (x); BN_free (y); BN_free(z); BN_free(t); }; + BIGNUM * x {nullptr}; + BIGNUM * y {nullptr}; + BIGNUM * z {nullptr}; + BIGNUM * t {nullptr}; // projective coordinates + + EDDSAPoint () {} + EDDSAPoint (const EDDSAPoint& other) { *this = other; } + EDDSAPoint (EDDSAPoint&& other) { *this = std::move (other); } + EDDSAPoint (BIGNUM * x1, BIGNUM * y1, BIGNUM * z1 = nullptr, BIGNUM * t1 = nullptr) + : x(x1) + , y(y1) + , z(z1) + , t(t1) + {} + ~EDDSAPoint () { BN_free (x); BN_free (y); BN_free(z); BN_free(t); } EDDSAPoint& operator=(EDDSAPoint&& other) { - if (x) BN_free (x); x = other.x; other.x = nullptr; - if (y) BN_free (y); y = other.y; other.y = nullptr; - if (z) BN_free (z); z = other.z; other.z = nullptr; - if (t) BN_free (t); t = other.t; other.t = nullptr; + if (this != &other) + { + BN_free (x); x = other.x; other.x = nullptr; + BN_free (y); y = other.y; other.y = nullptr; + BN_free (z); z = other.z; other.z = nullptr; + BN_free (t); t = other.t; other.t = nullptr; + } return *this; } EDDSAPoint& operator=(const EDDSAPoint& other) { - if (x) BN_free (x); x = other.x ? BN_dup (other.x) : nullptr; - if (y) BN_free (y); y = other.y ? BN_dup (other.y) : nullptr; - if (z) BN_free (z); z = other.z ? BN_dup (other.z) : nullptr; - if (t) BN_free (t); t = other.t ? BN_dup (other.t) : nullptr; + if (this != &other) + { + BN_free (x); x = other.x ? BN_dup (other.x) : nullptr; + BN_free (y); y = other.y ? BN_dup (other.y) : nullptr; + BN_free (z); z = other.z ? BN_dup (other.z) : nullptr; + BN_free (t); t = other.t ? BN_dup (other.t) : nullptr; + } return *this; } From 346bf14b7bbac8cfbea3ac5be089907f1fc5d033 Mon Sep 17 00:00:00 2001 From: brain5lug Date: Fri, 29 Sep 2017 10:17:23 +0300 Subject: [PATCH 2/2] added missed invariant for MemoryPool --- libi2pd/util.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libi2pd/util.h b/libi2pd/util.h index 1a9b9a73..5297b3ed 100644 --- a/libi2pd/util.h +++ b/libi2pd/util.h @@ -33,6 +33,8 @@ namespace util template class MemoryPool { + BOOST_STATIC_ASSERT_MSG(sizeof(T) >= sizeof(void*), "size cannot be less that general pointer size"); + public: MemoryPool (): m_Head (nullptr) {}