diff --git a/extra/yassl/include/buffer.hpp b/extra/yassl/include/buffer.hpp index cdf44ee60a5..8d94675f5b0 100644 --- a/extra/yassl/include/buffer.hpp +++ b/extra/yassl/include/buffer.hpp @@ -28,6 +28,7 @@ #define yaSSL_BUFFER_HPP #include // assert +#include "yassl_types.hpp" // ysDelete #include "yassl_error.hpp" // Error #include "memory.hpp" // mySTL::auto_ptr #include "algorithm.hpp" // mySTL::swap @@ -183,7 +184,7 @@ inline void checked_delete(T* p) { typedef char complete_type[sizeof(T) ? 1 : -1]; (void)sizeof(complete_type); - delete p; + ysDelete(p); } diff --git a/extra/yassl/include/crypto_wrapper.hpp b/extra/yassl/include/crypto_wrapper.hpp index fa60c774cd9..ca9d870677e 100644 --- a/extra/yassl/include/crypto_wrapper.hpp +++ b/extra/yassl/include/crypto_wrapper.hpp @@ -43,7 +43,7 @@ namespace yaSSL { // Digest policy should implement a get_digest, update, and get sizes for pad and // digest -struct Digest { +struct Digest : public virtual_base { virtual void get_digest(byte*) = 0; virtual void get_digest(byte*, const byte*, unsigned int) = 0; virtual void update(const byte*, unsigned int) = 0; @@ -178,7 +178,7 @@ private: // BulkCipher policy should implement encrypt, decrypt, get block size, // and set keys for encrypt and decrypt -struct BulkCipher { +struct BulkCipher : public virtual_base { virtual void encrypt(byte*, const byte*, unsigned int) = 0; virtual void decrypt(byte*, const byte*, unsigned int) = 0; virtual void set_encryptKey(const byte*, const byte* = 0) = 0; @@ -308,7 +308,7 @@ private: // Authentication policy should implement sign, and verify -struct Auth { +struct Auth : public virtual_base { virtual void sign(byte*, const byte*, unsigned int, const RandomPool&) = 0; virtual bool verify(const byte*, unsigned int, const byte*, unsigned int) = 0; diff --git a/extra/yassl/include/socket_wrapper.hpp b/extra/yassl/include/socket_wrapper.hpp index 2a4ac142ec8..a103cca1b37 100644 --- a/extra/yassl/include/socket_wrapper.hpp +++ b/extra/yassl/include/socket_wrapper.hpp @@ -68,7 +68,7 @@ class Socket { socket_t socket_; // underlying socket descriptor public: explicit Socket(socket_t s = INVALID_SOCKET); - virtual ~Socket(); + ~Socket(); void set_fd(socket_t s); uint get_ready() const; diff --git a/extra/yassl/include/yassl_imp.hpp b/extra/yassl/include/yassl_imp.hpp index 52108b6aa1c..3de58901f8e 100644 --- a/extra/yassl/include/yassl_imp.hpp +++ b/extra/yassl/include/yassl_imp.hpp @@ -63,7 +63,7 @@ struct RecordLayerHeader { // base for all messages -struct Message { +struct Message : public virtual_base { virtual input_buffer& set(input_buffer&) =0; virtual output_buffer& get(output_buffer&) const =0; @@ -175,7 +175,7 @@ private: // Base Class for all handshake messages -class HandShakeBase { +class HandShakeBase : public virtual_base { int length_; public: int get_length() const; @@ -327,7 +327,7 @@ private: }; -struct ServerKeyBase { +struct ServerKeyBase : public virtual_base { virtual ~ServerKeyBase() {} virtual void build(SSL&) {} virtual void read(SSL&, input_buffer&) {} @@ -342,7 +342,7 @@ struct Fortezza_Server : public ServerKeyBase { }; -struct SignatureBase { +struct SignatureBase : public virtual_base { virtual ~SignatureBase() {} }; @@ -461,7 +461,7 @@ struct PreMasterSecret { }; -struct ClientKeyBase { +struct ClientKeyBase : public virtual_base { virtual ~ClientKeyBase() {} virtual void build(SSL&) {} virtual void read(SSL&, input_buffer&) {} diff --git a/extra/yassl/include/yassl_types.hpp b/extra/yassl/include/yassl_types.hpp index 28f673f920d..fc6bef89aab 100644 --- a/extra/yassl/include/yassl_types.hpp +++ b/extra/yassl/include/yassl_types.hpp @@ -28,10 +28,55 @@ #define yaSSL_TYPES_HPP #include +#include +#include "type_traits.hpp" namespace yaSSL { +// library allocation +struct new_t {}; // yaSSL New type +extern new_t ys; // pass in parameter + +} // namespace yaSSL + +void* operator new (size_t, yaSSL::new_t); +void* operator new[](size_t, yaSSL::new_t); + +void operator delete (void*, yaSSL::new_t); +void operator delete[](void*, yaSSL::new_t); + + +namespace yaSSL { + + +template +void ysDelete(T* ptr) +{ + if (ptr) ptr->~T(); + ::operator delete(ptr, yaSSL::ys); +} + +template +void ysArrayDelete(T* ptr) +{ + // can't do array placement destruction since not tracking size in + // allocation, only allow builtins to use array placement since they + // don't need destructors called + typedef char builtin[TaoCrypt::IsFundamentalType::Yes ? 1 : -1]; + (void)sizeof(builtin); + + ::operator delete[](ptr, yaSSL::ys); +} + + +// to resolve compiler generated operator delete on base classes with +// virtual destructors, make sure doesn't get called +class virtual_base { +public: + static void operator delete(void*) { assert(0); } +}; + typedef unsigned char uint8; typedef unsigned short uint16; diff --git a/extra/yassl/mySTL/helpers.hpp b/extra/yassl/mySTL/helpers.hpp index 779389e322a..5f9b4beaa40 100644 --- a/extra/yassl/mySTL/helpers.hpp +++ b/extra/yassl/mySTL/helpers.hpp @@ -28,6 +28,7 @@ #define mySTL_HELPERS_HPP #include +#include // placement new #ifdef __IBMCPP__ diff --git a/extra/yassl/mySTL/list.hpp b/extra/yassl/mySTL/list.hpp index be149b1a984..8aaeefaafe8 100644 --- a/extra/yassl/mySTL/list.hpp +++ b/extra/yassl/mySTL/list.hpp @@ -29,7 +29,7 @@ #include "helpers.hpp" -#include // ::operator new and delete, placement too +#include namespace mySTL { @@ -38,13 +38,15 @@ namespace mySTL { template class list { + #ifdef __SUNPRO_CC /* - Sun Forte 7 C++ v. 5.4 needs class 'node' be public to be visible to - the nested class 'iterator' (a non-standard behaviour). + Sun Forte 7 C++ v. 5.4 needs class 'node' public to be visible to + the nested class 'iterator' (a non-standard behaviour). */ public: #endif + struct node { node(T t) : prev_(0), next_(0), value_(t) {} @@ -94,22 +96,22 @@ public: return *this; } - iterator& operator++(int) + iterator operator++(int) { iterator tmp = *this; current_ = current_->next_; - return *this; + return tmp; } - iterator& operator--(int) + iterator operator--(int) { iterator tmp = *this; current_ = current_->prev_; - return *this; + return tmp; } bool operator==(const iterator& other) const - { + { return current_ == other.current_; } @@ -152,7 +154,7 @@ list::~list() for (; start; start = next_) { next_ = start->next_; destroy(start); - ::operator delete(start); + free(start); } } @@ -160,7 +162,7 @@ list::~list() template void list::push_front(T t) { - void* mem = ::operator new(sizeof(node)); + void* mem = malloc(sizeof(node)); if (!mem) abort(); node* add = new (mem) node(t); @@ -190,7 +192,7 @@ void list::pop_front() head_->prev_ = 0; } destroy(front); - ::operator delete(front); + free(front); --sz_; } @@ -206,7 +208,7 @@ T list::front() const template void list::push_back(T t) { - void* mem = ::operator new(sizeof(node)); + void* mem = malloc(sizeof(node)); if (!mem) abort(); node* add = new (mem) node(t); @@ -236,7 +238,7 @@ void list::pop_back() tail_->next_ = 0; } destroy(rear); - ::operator delete(rear); + free(rear); --sz_; } @@ -280,7 +282,7 @@ bool list::remove(T t) del->next_->prev_ = del->prev_; destroy(del); - ::operator delete(del); + free(del); --sz_; } return true; @@ -303,7 +305,7 @@ bool list::erase(iterator iter) del->next_->prev_ = del->prev_; destroy(del); - ::operator delete(del); + free(del); --sz_; } return true; diff --git a/extra/yassl/mySTL/memory.hpp b/extra/yassl/mySTL/memory.hpp index 4049ed80813..729abae7ebc 100644 --- a/extra/yassl/mySTL/memory.hpp +++ b/extra/yassl/mySTL/memory.hpp @@ -37,30 +37,42 @@ namespace mySTL { -template +template struct auto_ptr_ref { - T* ptr_; - explicit auto_ptr_ref(T* p) : ptr_(p) {} + T* ptr_; + Deletor del_; + auto_ptr_ref(T* p, Deletor d) : ptr_(p), del_(d) {} }; -template +template class auto_ptr { - T* ptr_; + T* ptr_; + Deletor del_; + + void Destroy() + { + del_(ptr_); + } public: - explicit auto_ptr(T* p = 0) : ptr_(p) {} + auto_ptr(T* p, Deletor d) : ptr_(p), del_(d) {} + + explicit auto_ptr(Deletor d) : ptr_(0), del_(d) {} + ~auto_ptr() { - delete ptr_; + Destroy(); } - auto_ptr(auto_ptr& other) : ptr_(other.release()) {} + auto_ptr(auto_ptr& other) : ptr_(other.release()), del_(other.del_) {} + auto_ptr& operator=(auto_ptr& that) { if (this != &that) { - delete ptr_; + Destroy(); ptr_ = that.release(); + del_ = that.del_; } return *this; } @@ -91,19 +103,20 @@ public: void reset(T* p = 0) { if (ptr_ != p) { - delete ptr_; + Destroy(); ptr_ = p; } } // auto_ptr_ref conversions - auto_ptr(auto_ptr_ref ref) : ptr_(ref.ptr_) {} + auto_ptr(auto_ptr_ref ref) : ptr_(ref.ptr_), del_(ref.del_) {} auto_ptr& operator=(auto_ptr_ref ref) { if (this->ptr_ != ref.ptr_) { - delete ptr_; + Destroy(); ptr_ = ref.ptr_; + del_ = ref.del_; } return *this; } @@ -111,13 +124,13 @@ public: template operator auto_ptr() { - return auto_ptr(this->release()); + return auto_ptr(this->release(), this->del_); } template operator auto_ptr_ref() { - return auto_ptr_ref(this->release()); + return auto_ptr_ref(this->release(), this->del_); } }; diff --git a/extra/yassl/mySTL/vector.hpp b/extra/yassl/mySTL/vector.hpp index 6d5a9b6c057..e7f63c37c7c 100644 --- a/extra/yassl/mySTL/vector.hpp +++ b/extra/yassl/mySTL/vector.hpp @@ -27,11 +27,10 @@ #ifndef mySTL_VECTOR_HPP #define mySTL_VECTOR_HPP - #include "helpers.hpp" // construct, destory, fill, etc. #include "algorithm.hpp" // swap -#include // ::operator new and delete, placement too #include // assert +#include // malloc namespace mySTL { @@ -46,13 +45,13 @@ struct vector_base { vector_base() : start_(0), finish_(0), end_of_storage_(0) {} vector_base(size_t n) { - start_ = static_cast(::operator new(n * sizeof(T))); + start_ = static_cast(malloc(n * sizeof(T))); if (!start_) abort(); finish_ = start_; end_of_storage_ = start_ + n; } - ~vector_base() { ::operator delete(start_); } + ~vector_base() { if (start_) free(start_); } void Swap(vector_base& that) { diff --git a/extra/yassl/src/Makefile.am b/extra/yassl/src/Makefile.am index 3dbd7bac03a..1f5f1ee7a4e 100644 --- a/extra/yassl/src/Makefile.am +++ b/extra/yassl/src/Makefile.am @@ -3,5 +3,5 @@ INCLUDES = -I../include -I../taocrypt/include -I../mySTL noinst_LIBRARIES = libyassl.a libyassl_a_SOURCES = buffer.cpp cert_wrapper.cpp crypto_wrapper.cpp \ handshake.cpp lock.cpp log.cpp socket_wrapper.cpp ssl.cpp \ - timer.cpp yassl_imp.cpp yassl_error.cpp yassl_int.cpp + template_instnt.cpp timer.cpp yassl_imp.cpp yassl_error.cpp yassl_int.cpp EXTRA_DIST = ../include/*.hpp ../include/openssl/*.h diff --git a/extra/yassl/src/buffer.cpp b/extra/yassl/src/buffer.cpp index 6dc8845559c..a3a09121800 100644 --- a/extra/yassl/src/buffer.cpp +++ b/extra/yassl/src/buffer.cpp @@ -24,7 +24,6 @@ * with SSL types and sockets */ -#include "runtime.hpp" #include "buffer.hpp" #include "yassl_types.hpp" @@ -62,13 +61,13 @@ input_buffer::input_buffer() input_buffer::input_buffer(uint s) - : size_(0), current_(0), buffer_(new byte[s]), end_(buffer_ + s) + : size_(0), current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s) {} // with assign input_buffer::input_buffer(uint s, const byte* t, uint len) - : size_(0), current_(0), buffer_(new byte[s]), end_(buffer_ + s) + : size_(0), current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s) { assign(t, len); } @@ -76,7 +75,7 @@ input_buffer::input_buffer(uint s, const byte* t, uint len) input_buffer::~input_buffer() { - delete [] buffer_; + ysArrayDelete(buffer_); } @@ -84,7 +83,7 @@ input_buffer::~input_buffer() void input_buffer::allocate(uint s) { assert(!buffer_); // find realloc error - buffer_ = new byte[s]; + buffer_ = new (ys) byte[s]; end_ = buffer_ + s; } @@ -96,7 +95,7 @@ byte* input_buffer::get_buffer() const } -// after a raw write user can set new size +// after a raw write user can set new (ys) size // if you know the size before the write use assign() void input_buffer::add_size(uint i) { @@ -198,13 +197,13 @@ output_buffer::output_buffer() // with allocate output_buffer::output_buffer(uint s) - : current_(0), buffer_(new byte[s]), end_(buffer_ + s) + : current_(0), buffer_(new (ys) byte[s]), end_(buffer_ + s) {} // with assign output_buffer::output_buffer(uint s, const byte* t, uint len) - : current_(0), buffer_(new byte[s]), end_(buffer_+ s) + : current_(0), buffer_(new (ys) byte[s]), end_(buffer_+ s) { write(t, len); } @@ -212,7 +211,7 @@ output_buffer::output_buffer(uint s, const byte* t, uint len) output_buffer::~output_buffer() { - delete [] buffer_; + ysArrayDelete(buffer_); } @@ -239,7 +238,7 @@ void output_buffer::set_current(uint c) void output_buffer::allocate(uint s) { assert(!buffer_); // find realloc error - buffer_ = new byte[s]; end_ = buffer_ + s; + buffer_ = new (ys) byte[s]; end_ = buffer_ + s; } diff --git a/extra/yassl/src/cert_wrapper.cpp b/extra/yassl/src/cert_wrapper.cpp index 33c1fee6ec3..7a8c7dfe253 100644 --- a/extra/yassl/src/cert_wrapper.cpp +++ b/extra/yassl/src/cert_wrapper.cpp @@ -24,7 +24,6 @@ * */ -#include "runtime.hpp" #include "cert_wrapper.hpp" #include "yassl_int.hpp" @@ -39,19 +38,19 @@ namespace yaSSL { -x509::x509(uint sz) : length_(sz), buffer_(new opaque[sz]) +x509::x509(uint sz) : length_(sz), buffer_(new (ys) opaque[sz]) { } x509::~x509() { - delete [] buffer_; + ysArrayDelete(buffer_); } x509::x509(const x509& that) : length_(that.length_), - buffer_(new opaque[length_]) + buffer_(new (ys) opaque[length_]) { memcpy(buffer_, that.buffer_, length_); } @@ -98,7 +97,7 @@ CertManager::CertManager() CertManager::~CertManager() { - delete peerX509_; + ysDelete(peerX509_); mySTL::for_each(signers_.begin(), signers_.end(), del_ptr_zero()) ; @@ -153,7 +152,7 @@ void CertManager::AddPeerCert(x509* x) void CertManager::CopySelfCert(const x509* x) { if (x) - list_.push_back(new x509(*x)); + list_.push_back(new (ys) x509(*x)); } @@ -165,7 +164,7 @@ int CertManager::CopyCaCert(const x509* x) if (!cert.GetError().What()) { const TaoCrypt::PublicKey& key = cert.GetPublicKey(); - signers_.push_back(new TaoCrypt::Signer(key.GetKey(), key.size(), + signers_.push_back(new (ys) TaoCrypt::Signer(key.GetKey(), key.size(), cert.GetCommonName(), cert.GetHash())); } return cert.GetError().What(); @@ -234,7 +233,7 @@ int CertManager::Validate() return err; const TaoCrypt::PublicKey& key = cert.GetPublicKey(); - signers_.push_back(new TaoCrypt::Signer(key.GetKey(), key.size(), + signers_.push_back(new (ys) TaoCrypt::Signer(key.GetKey(), key.size(), cert.GetCommonName(), cert.GetHash())); --last; --count; @@ -259,7 +258,7 @@ int CertManager::Validate() int iSz = cert.GetIssuer() ? strlen(cert.GetIssuer()) + 1 : 0; int sSz = cert.GetCommonName() ? strlen(cert.GetCommonName()) + 1 : 0; - peerX509_ = new X509(cert.GetIssuer(), iSz, cert.GetCommonName(), + peerX509_ = new (ys) X509(cert.GetIssuer(), iSz, cert.GetCommonName(), sSz); } return 0; diff --git a/extra/yassl/src/crypto_wrapper.cpp b/extra/yassl/src/crypto_wrapper.cpp index e6b28cd9302..ff1b4b630c2 100644 --- a/extra/yassl/src/crypto_wrapper.cpp +++ b/extra/yassl/src/crypto_wrapper.cpp @@ -58,13 +58,13 @@ struct MD5::MD5Impl { }; -MD5::MD5() : pimpl_(new MD5Impl) {} +MD5::MD5() : pimpl_(new (ys) MD5Impl) {} -MD5::~MD5() { delete pimpl_; } +MD5::~MD5() { ysDelete(pimpl_); } -MD5::MD5(const MD5& that) : Digest(), pimpl_(new +MD5::MD5(const MD5& that) : Digest(), pimpl_(new (ys) MD5Impl(that.pimpl_->md5_)) {} @@ -116,13 +116,13 @@ struct SHA::SHAImpl { }; -SHA::SHA() : pimpl_(new SHAImpl) {} +SHA::SHA() : pimpl_(new (ys) SHAImpl) {} -SHA::~SHA() { delete pimpl_; } +SHA::~SHA() { ysDelete(pimpl_); } -SHA::SHA(const SHA& that) : Digest(), pimpl_(new SHAImpl(that.pimpl_->sha_)) {} +SHA::SHA(const SHA& that) : Digest(), pimpl_(new (ys) SHAImpl(that.pimpl_->sha_)) {} SHA& SHA::operator=(const SHA& that) { @@ -173,13 +173,13 @@ struct RMD::RMDImpl { }; -RMD::RMD() : pimpl_(new RMDImpl) {} +RMD::RMD() : pimpl_(new (ys) RMDImpl) {} -RMD::~RMD() { delete pimpl_; } +RMD::~RMD() { ysDelete(pimpl_); } -RMD::RMD(const RMD& that) : Digest(), pimpl_(new RMDImpl(that.pimpl_->rmd_)) {} +RMD::RMD(const RMD& that) : Digest(), pimpl_(new (ys) RMDImpl(that.pimpl_->rmd_)) {} RMD& RMD::operator=(const RMD& that) { @@ -230,13 +230,13 @@ struct HMAC_MD5::HMAC_MD5Impl { HMAC_MD5::HMAC_MD5(const byte* secret, unsigned int len) - : pimpl_(new HMAC_MD5Impl) + : pimpl_(new (ys) HMAC_MD5Impl) { pimpl_->mac_.SetKey(secret, len); } -HMAC_MD5::~HMAC_MD5() { delete pimpl_; } +HMAC_MD5::~HMAC_MD5() { ysDelete(pimpl_); } uint HMAC_MD5::get_digestSize() const @@ -280,13 +280,13 @@ struct HMAC_SHA::HMAC_SHAImpl { HMAC_SHA::HMAC_SHA(const byte* secret, unsigned int len) - : pimpl_(new HMAC_SHAImpl) + : pimpl_(new (ys) HMAC_SHAImpl) { pimpl_->mac_.SetKey(secret, len); } -HMAC_SHA::~HMAC_SHA() { delete pimpl_; } +HMAC_SHA::~HMAC_SHA() { ysDelete(pimpl_); } uint HMAC_SHA::get_digestSize() const @@ -331,13 +331,13 @@ struct HMAC_RMD::HMAC_RMDImpl { HMAC_RMD::HMAC_RMD(const byte* secret, unsigned int len) - : pimpl_(new HMAC_RMDImpl) + : pimpl_(new (ys) HMAC_RMDImpl) { pimpl_->mac_.SetKey(secret, len); } -HMAC_RMD::~HMAC_RMD() { delete pimpl_; } +HMAC_RMD::~HMAC_RMD() { ysDelete(pimpl_); } uint HMAC_RMD::get_digestSize() const @@ -379,9 +379,9 @@ struct DES::DESImpl { }; -DES::DES() : pimpl_(new DESImpl) {} +DES::DES() : pimpl_(new (ys) DESImpl) {} -DES::~DES() { delete pimpl_; } +DES::~DES() { ysDelete(pimpl_); } void DES::set_encryptKey(const byte* k, const byte* iv) @@ -415,9 +415,9 @@ struct DES_EDE::DES_EDEImpl { }; -DES_EDE::DES_EDE() : pimpl_(new DES_EDEImpl) {} +DES_EDE::DES_EDE() : pimpl_(new (ys) DES_EDEImpl) {} -DES_EDE::~DES_EDE() { delete pimpl_; } +DES_EDE::~DES_EDE() { ysDelete(pimpl_); } void DES_EDE::set_encryptKey(const byte* k, const byte* iv) @@ -453,9 +453,9 @@ struct RC4::RC4Impl { }; -RC4::RC4() : pimpl_(new RC4Impl) {} +RC4::RC4() : pimpl_(new (ys) RC4Impl) {} -RC4::~RC4() { delete pimpl_; } +RC4::~RC4() { ysDelete(pimpl_); } void RC4::set_encryptKey(const byte* k, const byte*) @@ -495,9 +495,9 @@ struct AES::AESImpl { }; -AES::AES(unsigned int ks) : pimpl_(new AESImpl(ks)) {} +AES::AES(unsigned int ks) : pimpl_(new (ys) AESImpl(ks)) {} -AES::~AES() { delete pimpl_; } +AES::~AES() { ysDelete(pimpl_); } int AES::get_keySize() const @@ -536,9 +536,9 @@ struct RandomPool::RandomImpl { TaoCrypt::RandomNumberGenerator RNG_; }; -RandomPool::RandomPool() : pimpl_(new RandomImpl) {} +RandomPool::RandomPool() : pimpl_(new (ys) RandomImpl) {} -RandomPool::~RandomPool() { delete pimpl_; } +RandomPool::~RandomPool() { ysDelete(pimpl_); } int RandomPool::GetError() const { @@ -580,7 +580,7 @@ void DSS::DSSImpl::SetPrivate(const byte* key, unsigned int sz) // Set public or private key DSS::DSS(const byte* key, unsigned int sz, bool publicKey) - : pimpl_(new DSSImpl) + : pimpl_(new (ys) DSSImpl) { if (publicKey) pimpl_->SetPublic(key, sz); @@ -591,7 +591,7 @@ DSS::DSS(const byte* key, unsigned int sz, bool publicKey) DSS::~DSS() { - delete pimpl_; + ysDelete(pimpl_); } @@ -651,7 +651,7 @@ void RSA::RSAImpl::SetPrivate(const byte* key, unsigned int sz) // Set public or private key RSA::RSA(const byte* key, unsigned int sz, bool publicKey) - : pimpl_(new RSAImpl) + : pimpl_(new (ys) RSAImpl) { if (publicKey) pimpl_->SetPublic(key, sz); @@ -661,7 +661,7 @@ RSA::RSA(const byte* key, unsigned int sz, bool publicKey) RSA::~RSA() { - delete pimpl_; + ysDelete(pimpl_); } @@ -723,13 +723,13 @@ struct Integer::IntegerImpl { explicit IntegerImpl(const TaoCrypt::Integer& i) : int_(i) {} }; -Integer::Integer() : pimpl_(new IntegerImpl) {} +Integer::Integer() : pimpl_(new (ys) IntegerImpl) {} -Integer::~Integer() { delete pimpl_; } +Integer::~Integer() { ysDelete(pimpl_); } -Integer::Integer(const Integer& other) : pimpl_(new +Integer::Integer(const Integer& other) : pimpl_(new (ys) IntegerImpl(other.pimpl_->int_)) {} @@ -757,7 +757,12 @@ struct DiffieHellman::DHImpl { DHImpl(TaoCrypt::RandomNumberGenerator& r) : ranPool_(r), publicKey_(0), privateKey_(0), agreedKey_(0) {} - ~DHImpl() {delete[] agreedKey_; delete[] privateKey_; delete[] publicKey_;} + ~DHImpl() + { + ysArrayDelete(agreedKey_); + ysArrayDelete(privateKey_); + ysArrayDelete(publicKey_); + } DHImpl(const DHImpl& that) : dh_(that.dh_), ranPool_(that.ranPool_), publicKey_(0), privateKey_(0), agreedKey_(0) @@ -768,9 +773,9 @@ struct DiffieHellman::DHImpl { void AllocKeys(unsigned int pubSz, unsigned int privSz, unsigned int agrSz) { - publicKey_ = new byte[pubSz]; - privateKey_ = new byte[privSz]; - agreedKey_ = new byte[agrSz]; + publicKey_ = new (ys) byte[pubSz]; + privateKey_ = new (ys) byte[privSz]; + agreedKey_ = new (ys) byte[agrSz]; } }; @@ -779,7 +784,7 @@ struct DiffieHellman::DHImpl { /* // server Side DH, server's view DiffieHellman::DiffieHellman(const char* file, const RandomPool& random) - : pimpl_(new DHImpl(random.pimpl_->RNG_)) + : pimpl_(new (ys) DHImpl(random.pimpl_->RNG_)) { using namespace TaoCrypt; Source source; @@ -803,12 +808,12 @@ DiffieHellman::DiffieHellman(const char* file, const RandomPool& random) DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g, unsigned int gSz, const byte* pub, unsigned int pubSz, const RandomPool& random) - : pimpl_(new DHImpl(random.pimpl_->RNG_)) + : pimpl_(new (ys) DHImpl(random.pimpl_->RNG_)) { using TaoCrypt::Integer; pimpl_->dh_.Initialize(Integer(p, pSz).Ref(), Integer(g, gSz).Ref()); - pimpl_->publicKey_ = new opaque[pubSz]; + pimpl_->publicKey_ = new (ys) opaque[pubSz]; memcpy(pimpl_->publicKey_, pub, pubSz); } @@ -816,7 +821,7 @@ DiffieHellman::DiffieHellman(const byte* p, unsigned int pSz, const byte* g, // Server Side DH, server's view DiffieHellman::DiffieHellman(const Integer& p, const Integer& g, const RandomPool& random) -: pimpl_(new DHImpl(random.pimpl_->RNG_)) +: pimpl_(new (ys) DHImpl(random.pimpl_->RNG_)) { using TaoCrypt::Integer; @@ -829,12 +834,12 @@ DiffieHellman::DiffieHellman(const Integer& p, const Integer& g, pimpl_->publicKey_); } -DiffieHellman::~DiffieHellman() { delete pimpl_; } +DiffieHellman::~DiffieHellman() { ysDelete(pimpl_); } // Client side and view, use server that for p and g DiffieHellman::DiffieHellman(const DiffieHellman& that) - : pimpl_(new DHImpl(*that.pimpl_)) + : pimpl_(new (ys) DHImpl(*that.pimpl_)) { pimpl_->dh_.GenerateKeyPair(pimpl_->ranPool_, pimpl_->privateKey_, pimpl_->publicKey_); @@ -955,7 +960,7 @@ x509* PemToDer(const char* fname, CertType type) Base64Decoder b64Dec(der); uint sz = der.size(); - mySTL::auto_ptr x(new x509(sz)); + mySTL::auto_ptr x(new (ys) x509(sz), ysDelete); memcpy(x->use_buffer(), der.get_buffer(), sz); fclose(file); @@ -965,10 +970,25 @@ x509* PemToDer(const char* fname, CertType type) } // namespace + #ifdef __GNUC__ -template class TaoCrypt::HMAC; -template class TaoCrypt::HMAC; -template class TaoCrypt::HMAC; -#endif +namespace yaSSL { +template void ysDelete(DiffieHellman::DHImpl*); +template void ysDelete(Integer::IntegerImpl*); +template void ysDelete(RSA::RSAImpl*); +template void ysDelete(DSS::DSSImpl*); +template void ysDelete(RandomPool::RandomImpl*); +template void ysDelete(AES::AESImpl*); +template void ysDelete(RC4::RC4Impl*); +template void ysDelete(DES_EDE::DES_EDEImpl*); +template void ysDelete(DES::DESImpl*); +template void ysDelete(HMAC_RMD::HMAC_RMDImpl*); +template void ysDelete(HMAC_SHA::HMAC_SHAImpl*); +template void ysDelete(HMAC_MD5::HMAC_MD5Impl*); +template void ysDelete(RMD::RMDImpl*); +template void ysDelete(SHA::SHAImpl*); +template void ysDelete(MD5::MD5Impl*); +} +#endif // __GNUC__ #endif // !USE_CRYPTOPP_LIB diff --git a/extra/yassl/src/handshake.cpp b/extra/yassl/src/handshake.cpp index 28872e50063..e49d1ec76cc 100644 --- a/extra/yassl/src/handshake.cpp +++ b/extra/yassl/src/handshake.cpp @@ -357,14 +357,14 @@ void p_hash(output_buffer& result, const output_buffer& secret, uint lastLen = result.get_capacity() % len; opaque previous[SHA_LEN]; // max size opaque current[SHA_LEN]; // max size - mySTL::auto_ptr hmac; + mySTL::auto_ptr hmac(ysDelete); if (lastLen) times += 1; if (hash == md5) - hmac.reset(new HMAC_MD5(secret.get_buffer(), secret.get_size())); + hmac.reset(new (ys) HMAC_MD5(secret.get_buffer(), secret.get_size())); else - hmac.reset(new HMAC_SHA(secret.get_buffer(), secret.get_size())); + hmac.reset(new (ys) HMAC_SHA(secret.get_buffer(), secret.get_size())); // A0 = seed hmac->get_digest(previous, seed.get_buffer(), seed.get_size());// A1 uint lastTime = times - 1; @@ -571,7 +571,7 @@ void hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz, void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz, ContentType content, bool verify) { - mySTL::auto_ptr hmac; + mySTL::auto_ptr hmac(ysDelete); opaque seq[SEQ_SZ] = { 0x00, 0x00, 0x00, 0x00 }; opaque length[LENGTH_SZ]; opaque inner[SIZEOF_ENUM + VERSION_SZ + LENGTH_SZ]; // type + version + len @@ -582,11 +582,11 @@ void TLS_hmac(SSL& ssl, byte* digest, const byte* buffer, uint sz, MACAlgorithm algo = ssl.getSecurity().get_parms().mac_algorithm_; if (algo == sha) - hmac.reset(new HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN)); + hmac.reset(new (ys) HMAC_SHA(ssl.get_macSecret(verify), SHA_LEN)); else if (algo == rmd) - hmac.reset(new HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN)); + hmac.reset(new (ys) HMAC_RMD(ssl.get_macSecret(verify), RMD_LEN)); else - hmac.reset(new HMAC_MD5(ssl.get_macSecret(verify), MD5_LEN)); + hmac.reset(new (ys) HMAC_MD5(ssl.get_macSecret(verify), MD5_LEN)); hmac->update(seq, SEQ_SZ); // seq_num inner[0] = content; // type @@ -648,7 +648,7 @@ void build_certHashes(SSL& ssl, Hashes& hashes) } -mySTL::auto_ptr null_buffer; +mySTL::auto_ptr null_buffer(ysDelete); // do process input requests mySTL::auto_ptr @@ -666,7 +666,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr buffered) buffered = null_buffer; } - // add new data + // add new (ys) data uint read = ssl.getSocket().receive(buffer.get_buffer() + buffSz, ready); buffer.add_size(read); uint offset = 0; @@ -687,7 +687,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr buffered) // make sure we have enough input in buffer to process this record if (hdr.length_ > buffer.get_remaining()) { uint sz = buffer.get_remaining() + RECORD_HEADER; - buffered.reset(new input_buffer(sz, buffer.get_buffer() + + buffered.reset(new (ys) input_buffer(sz, buffer.get_buffer() + buffer.get_current() - RECORD_HEADER, sz)); break; } @@ -696,7 +696,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr buffered) // each message in record if (ssl.getSecurity().get_parms().pending_ == false) // cipher on decrypt_message(ssl, buffer, hdr.length_); - mySTL::auto_ptr msg(mf.CreateObject(hdr.type_)); + mySTL::auto_ptr msg(mf.CreateObject(hdr.type_), ysDelete); if (!msg.get()) { ssl.SetError(factory_error); return buffered = null_buffer; @@ -715,7 +715,7 @@ DoProcessReply(SSL& ssl, mySTL::auto_ptr buffered) void processReply(SSL& ssl) { if (ssl.GetError()) return; - mySTL::auto_ptr buffered; + mySTL::auto_ptr buffered(ysDelete); for (;;) { mySTL::auto_ptr tmp = DoProcessReply(ssl, buffered); @@ -760,7 +760,7 @@ void sendClientKeyExchange(SSL& ssl, BufferOutput buffer) RecordLayerHeader rlHeader; HandShakeHeader hsHeader; - mySTL::auto_ptr out(new output_buffer); + mySTL::auto_ptr out(new (ys) output_buffer, ysDelete); buildHeaders(ssl, hsHeader, rlHeader, ck); buildOutput(*out.get(), rlHeader, hsHeader, ck); hashHandShake(ssl, *out.get()); @@ -781,7 +781,7 @@ void sendServerKeyExchange(SSL& ssl, BufferOutput buffer) RecordLayerHeader rlHeader; HandShakeHeader hsHeader; - mySTL::auto_ptr out(new output_buffer); + mySTL::auto_ptr out(new (ys) output_buffer, ysDelete); buildHeaders(ssl, hsHeader, rlHeader, sk); buildOutput(*out.get(), rlHeader, hsHeader, sk); hashHandShake(ssl, *out.get()); @@ -806,7 +806,7 @@ void sendChangeCipher(SSL& ssl, BufferOutput buffer) ChangeCipherSpec ccs; RecordLayerHeader rlHeader; buildHeader(ssl, rlHeader, ccs); - mySTL::auto_ptr out(new output_buffer); + mySTL::auto_ptr out(new (ys) output_buffer, ysDelete); buildOutput(*out.get(), rlHeader, ccs); if (buffer == buffered) @@ -823,7 +823,7 @@ void sendFinished(SSL& ssl, ConnectionEnd side, BufferOutput buffer) Finished fin; buildFinished(ssl, fin, side == client_end ? client : server); - mySTL::auto_ptr out(new output_buffer); + mySTL::auto_ptr out(new (ys) output_buffer, ysDelete); cipherFinished(ssl, fin, *out.get()); // hashes handshake if (ssl.getSecurity().get_resuming()) { @@ -907,7 +907,7 @@ void sendServerHello(SSL& ssl, BufferOutput buffer) ServerHello sh(ssl.getSecurity().get_connection().version_); RecordLayerHeader rlHeader; HandShakeHeader hsHeader; - mySTL::auto_ptr out(new output_buffer); + mySTL::auto_ptr out(new (ys) output_buffer, ysDelete); buildServerHello(ssl, sh); ssl.set_random(sh.get_random(), server_end); @@ -930,7 +930,7 @@ void sendServerHelloDone(SSL& ssl, BufferOutput buffer) ServerHelloDone shd; RecordLayerHeader rlHeader; HandShakeHeader hsHeader; - mySTL::auto_ptr out(new output_buffer); + mySTL::auto_ptr out(new (ys) output_buffer, ysDelete); buildHeaders(ssl, hsHeader, rlHeader, shd); buildOutput(*out.get(), rlHeader, hsHeader, shd); @@ -951,7 +951,7 @@ void sendCertificate(SSL& ssl, BufferOutput buffer) Certificate cert(ssl.getCrypto().get_certManager().get_cert()); RecordLayerHeader rlHeader; HandShakeHeader hsHeader; - mySTL::auto_ptr out(new output_buffer); + mySTL::auto_ptr out(new (ys) output_buffer, ysDelete); buildHeaders(ssl, hsHeader, rlHeader, cert); buildOutput(*out.get(), rlHeader, hsHeader, cert); @@ -973,7 +973,7 @@ void sendCertificateRequest(SSL& ssl, BufferOutput buffer) request.Build(); RecordLayerHeader rlHeader; HandShakeHeader hsHeader; - mySTL::auto_ptr out(new output_buffer); + mySTL::auto_ptr out(new (ys) output_buffer, ysDelete); buildHeaders(ssl, hsHeader, rlHeader, request); buildOutput(*out.get(), rlHeader, hsHeader, request); @@ -995,7 +995,7 @@ void sendCertificateVerify(SSL& ssl, BufferOutput buffer) verify.Build(ssl); RecordLayerHeader rlHeader; HandShakeHeader hsHeader; - mySTL::auto_ptr out(new output_buffer); + mySTL::auto_ptr out(new (ys) output_buffer, ysDelete); buildHeaders(ssl, hsHeader, rlHeader, verify); buildOutput(*out.get(), rlHeader, hsHeader, verify); diff --git a/extra/yassl/src/lock.cpp b/extra/yassl/src/lock.cpp index 221ec0cdb4f..b8f6212ad3f 100644 --- a/extra/yassl/src/lock.cpp +++ b/extra/yassl/src/lock.cpp @@ -22,7 +22,6 @@ /* Locking functions */ -#include "runtime.hpp" #include "lock.hpp" diff --git a/extra/yassl/src/log.cpp b/extra/yassl/src/log.cpp index 19072a5e09c..538b80b8280 100644 --- a/extra/yassl/src/log.cpp +++ b/extra/yassl/src/log.cpp @@ -22,7 +22,6 @@ /* Debug logging functions */ -#include "runtime.hpp" #include "log.hpp" #ifdef YASSL_LOG diff --git a/extra/yassl/src/socket_wrapper.cpp b/extra/yassl/src/socket_wrapper.cpp index 0dd30e6b696..f0d530f187c 100644 --- a/extra/yassl/src/socket_wrapper.cpp +++ b/extra/yassl/src/socket_wrapper.cpp @@ -26,7 +26,6 @@ */ -#include "runtime.hpp" #include "socket_wrapper.hpp" #include "yassl_error.hpp" diff --git a/extra/yassl/src/ssl.cpp b/extra/yassl/src/ssl.cpp index b0d9dcca902..466884f3cd9 100644 --- a/extra/yassl/src/ssl.cpp +++ b/extra/yassl/src/ssl.cpp @@ -32,7 +32,6 @@ /* see man pages for function descriptions */ -#include "runtime.hpp" #include "openssl/ssl.h" #include "handshake.hpp" #include "yassl_int.hpp" @@ -52,25 +51,25 @@ SSL_METHOD* SSLv3_method() SSL_METHOD* SSLv3_server_method() { - return new SSL_METHOD(server_end, ProtocolVersion(3,0)); + return new (ys) SSL_METHOD(server_end, ProtocolVersion(3,0)); } SSL_METHOD* SSLv3_client_method() { - return new SSL_METHOD(client_end, ProtocolVersion(3,0)); + return new (ys) SSL_METHOD(client_end, ProtocolVersion(3,0)); } SSL_METHOD* TLSv1_server_method() { - return new SSL_METHOD(server_end, ProtocolVersion(3,1)); + return new (ys) SSL_METHOD(server_end, ProtocolVersion(3,1)); } SSL_METHOD* TLSv1_client_method() { - return new SSL_METHOD(client_end, ProtocolVersion(3,1)); + return new (ys) SSL_METHOD(client_end, ProtocolVersion(3,1)); } @@ -83,25 +82,25 @@ SSL_METHOD* SSLv23_server_method() SSL_CTX* SSL_CTX_new(SSL_METHOD* method) { - return new SSL_CTX(method); + return new (ys) SSL_CTX(method); } void SSL_CTX_free(SSL_CTX* ctx) { - delete ctx; + ysDelete(ctx); } SSL* SSL_new(SSL_CTX* ctx) { - return new SSL(ctx); + return new (ys) SSL(ctx); } void SSL_free(SSL* ssl) { - delete ssl; + ysDelete(ssl); } @@ -443,7 +442,7 @@ int read_file(SSL_CTX* ctx, const char* file, int format, CertType type) fseek(input, 0, SEEK_END); long sz = ftell(input); rewind(input); - x = new x509(sz); // takes ownership + x = new (ys) x509(sz); // takes ownership size_t bytes = fread(x->use_buffer(), sz, 1, input); if (bytes != 1) { fclose(input); @@ -638,7 +637,7 @@ void OpenSSL_add_all_algorithms() // compatibility only DH* DH_new(void) { - DH* dh = new DH; + DH* dh = new (ys) DH; if (dh) dh->p = dh->g = 0; return dh; @@ -647,9 +646,9 @@ DH* DH_new(void) void DH_free(DH* dh) { - delete dh->g; - delete dh->p; - delete dh; + ysDelete(dh->g); + ysDelete(dh->p); + ysDelete(dh); } @@ -659,11 +658,11 @@ BIGNUM* BN_bin2bn(const unsigned char* num, int sz, BIGNUM* retVal) { using mySTL::auto_ptr; bool created = false; - auto_ptr bn; + auto_ptr bn(ysDelete); if (!retVal) { created = true; - bn.reset(new BIGNUM); + bn.reset(new (ys) BIGNUM); retVal = bn.get(); } @@ -712,14 +711,14 @@ const char* X509_verify_cert_error_string(long /* error */) const EVP_MD* EVP_md5(void) { // TODO: FIX add to some list for destruction - return new MD5; + return new (ys) MD5; } const EVP_CIPHER* EVP_des_ede3_cbc(void) { // TODO: FIX add to some list for destruction - return new DES_EDE; + return new (ys) DES_EDE; } diff --git a/extra/yassl/src/template_instnt.cpp b/extra/yassl/src/template_instnt.cpp new file mode 100644 index 00000000000..4ad1ec29249 --- /dev/null +++ b/extra/yassl/src/template_instnt.cpp @@ -0,0 +1,67 @@ +#include "runtime.hpp" +#include "handshake.hpp" +#include "yassl_int.hpp" +#include "crypto_wrapper.hpp" +#include "hmac.hpp" +#include "md5.hpp" +#include "sha.hpp" +#include "ripemd.hpp" +#include "openssl/ssl.h" + +#ifdef __GNUC__ +#if !defined(USE_CRYPTOPP_LIB) +namespace TaoCrypt { +template class HMAC; +template class HMAC; +template class HMAC; +} +#endif + +namespace mySTL { +template class mySTL::list; +template yaSSL::del_ptr_zero mySTL::for_each(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); +template mySTL::pair* mySTL::uninit_copy*, mySTL::pair*>(mySTL::pair*, mySTL::pair*, mySTL::pair*); +template mySTL::pair* mySTL::uninit_copy*, mySTL::pair*>(mySTL::pair*, mySTL::pair*, mySTL::pair*); +template void mySTL::destroy*>(mySTL::pair*, mySTL::pair*); +template void mySTL::destroy*>(mySTL::pair*, mySTL::pair*); +template mySTL::pair* mySTL::uninit_copy*, mySTL::pair*>(mySTL::pair*, mySTL::pair*, mySTL::pair*); +template void mySTL::destroy*>(mySTL::pair*, mySTL::pair*); +template mySTL::pair* mySTL::uninit_copy*, mySTL::pair*>(mySTL::pair*, mySTL::pair*, mySTL::pair*); +template class mySTL::list; +template class mySTL::list; +template class mySTL::list; +template class mySTL::list; +template class mySTL::list; +template void mySTL::destroy*>(mySTL::pair*, mySTL::pair*); +template yaSSL::del_ptr_zero mySTL::for_each::iterator, yaSSL::del_ptr_zero>(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); +template yaSSL::del_ptr_zero mySTL::for_each::iterator, yaSSL::del_ptr_zero>(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); +template yaSSL::del_ptr_zero mySTL::for_each::iterator, yaSSL::del_ptr_zero>(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); +template yaSSL::del_ptr_zero mySTL::for_each::iterator, yaSSL::del_ptr_zero>(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); +template yaSSL::del_ptr_zero mySTL::for_each::iterator, yaSSL::del_ptr_zero>(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); +} + +namespace yaSSL { +template void ysDelete(yaSSL::SSL_CTX*); +template void ysDelete(yaSSL::SSL*); +template void ysDelete(yaSSL::BIGNUM*); +template void ysDelete(unsigned char*); +template void ysDelete(yaSSL::DH*); +template void ysDelete(TaoCrypt::Signer*); +template void ysDelete(yaSSL::SSL_SESSION*); +template void ysDelete(input_buffer*); +template void ysDelete(output_buffer*); +template void ysDelete(x509*); +template void ysDelete(Auth*); +template void ysDelete(HandShakeBase*); +template void ysDelete(ServerKeyBase*); +template void ysDelete(ClientKeyBase*); +template void ysDelete(SSL_METHOD*); +template void ysDelete(DiffieHellman*); +template void ysDelete(BulkCipher*); +template void ysDelete(Digest*); +template void ysDelete(X509*); +template void ysDelete(Message*); +template void ysArrayDelete(unsigned char*); +template void ysArrayDelete(char*); +} +#endif diff --git a/extra/yassl/src/timer.cpp b/extra/yassl/src/timer.cpp index 49e7bb36776..547c31205c6 100644 --- a/extra/yassl/src/timer.cpp +++ b/extra/yassl/src/timer.cpp @@ -23,7 +23,6 @@ * */ -#include "runtime.hpp" #include "timer.hpp" namespace yaSSL { diff --git a/extra/yassl/src/yassl_error.cpp b/extra/yassl/src/yassl_error.cpp index c53aef2068d..6ae5a9f6663 100644 --- a/extra/yassl/src/yassl_error.cpp +++ b/extra/yassl/src/yassl_error.cpp @@ -23,7 +23,6 @@ /* yaSSL error implements and an exception class */ -#include "runtime.hpp" #include "yassl_error.hpp" namespace yaSSL { diff --git a/extra/yassl/src/yassl_imp.cpp b/extra/yassl/src/yassl_imp.cpp index 02654727f78..1d9db46816b 100644 --- a/extra/yassl/src/yassl_imp.cpp +++ b/extra/yassl/src/yassl_imp.cpp @@ -130,14 +130,14 @@ void DH_Server::build(SSL& ssl) parms_.alloc_pub(pubSz)); short sigSz = 0; - mySTL::auto_ptr auth; + mySTL::auto_ptr auth(ysDelete); const CertManager& cert = ssl.getCrypto().get_certManager(); if (ssl.getSecurity().get_parms().sig_algo_ == rsa_sa_algo) - auth.reset(new RSA(cert.get_privateKey(), + auth.reset(new (ys) RSA(cert.get_privateKey(), cert.get_privateKeyLength(), false)); else { - auth.reset(new DSS(cert.get_privateKey(), + auth.reset(new (ys) DSS(cert.get_privateKey(), cert.get_privateKeyLength(), false)); sigSz += DSS_ENCODED_EXTRA; } @@ -168,7 +168,7 @@ void DH_Server::build(SSL& ssl) byte hash[FINISHED_SZ]; MD5 md5; SHA sha; - signature_ = new byte[sigSz]; + signature_ = new (ys) byte[sigSz]; const Connection& conn = ssl.getSecurity().get_connection(); // md5 @@ -199,7 +199,7 @@ void DH_Server::build(SSL& ssl) tmp.write(signature_, sigSz); // key message - keyMessage_ = new opaque[length_]; + keyMessage_ = new (ys) opaque[length_]; memcpy(keyMessage_, tmp.get_buffer(), tmp.get_size()); } @@ -234,7 +234,7 @@ EncryptedPreMasterSecret::EncryptedPreMasterSecret() EncryptedPreMasterSecret::~EncryptedPreMasterSecret() { - delete[] secret_; + ysArrayDelete(secret_); } @@ -253,7 +253,7 @@ opaque* EncryptedPreMasterSecret::get_clientKey() const void EncryptedPreMasterSecret::alloc(int sz) { length_ = sz; - secret_ = new opaque[sz]; + secret_ = new (ys) opaque[sz]; } @@ -284,7 +284,7 @@ ClientDiffieHellmanPublic::ClientDiffieHellmanPublic() ClientDiffieHellmanPublic::~ClientDiffieHellmanPublic() { - delete[] Yc_; + ysArrayDelete(Yc_); } @@ -303,7 +303,7 @@ opaque* ClientDiffieHellmanPublic::get_clientKey() const void ClientDiffieHellmanPublic::alloc(int sz, bool offset) { length_ = sz + (offset ? KEY_OFFSET : 0); - Yc_ = new opaque[length_]; + Yc_ = new (ys) opaque[length_]; } @@ -348,7 +348,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input) tmp[1] = input[AUTO]; ato16(tmp, length); - signature_ = new byte[length]; + signature_ = new (ys) byte[length]; input.read(signature_, length); // verify signature @@ -386,7 +386,7 @@ void DH_Server::read(SSL& ssl, input_buffer& input) } // save input - ssl.useCrypto().SetDH(new DiffieHellman(parms_.get_p(), + ssl.useCrypto().SetDH(new (ys) DiffieHellman(parms_.get_p(), parms_.get_pSize(), parms_.get_g(), parms_.get_gSize(), parms_.get_pub(), parms_.get_pubSize(), ssl.getCrypto().get_random())); @@ -400,8 +400,8 @@ DH_Server::DH_Server() DH_Server::~DH_Server() { - delete[] keyMessage_; - delete[] signature_; + ysArrayDelete(keyMessage_); + ysArrayDelete(signature_); } @@ -594,7 +594,7 @@ void HandShakeHeader::Process(input_buffer& input, SSL& ssl) { ssl.verifyState(*this); const HandShakeFactory& hsf = ssl.getFactory().getHandShake(); - mySTL::auto_ptr hs(hsf.CreateObject(type_)); + mySTL::auto_ptr hs(hsf.CreateObject(type_), ysDelete); if (!hs.get()) { ssl.SetError(factory_error); return; @@ -928,7 +928,7 @@ void Data::Process(input_buffer& input, SSL& ssl) // read data if (dataSz) { input_buffer* data; - ssl.addData(data = new input_buffer(dataSz)); + ssl.addData(data = new (ys) input_buffer(dataSz)); input.read(data->get_buffer(), dataSz); data->add_size(dataSz); @@ -1025,7 +1025,7 @@ void Certificate::Process(input_buffer& input, SSL& ssl) c24to32(tmp, cert_sz); x509* myCert; - cm.AddPeerCert(myCert = new x509(cert_sz)); + cm.AddPeerCert(myCert = new (ys) x509(cert_sz)); input.read(myCert->use_buffer(), myCert->get_length()); list_sz -= cert_sz + CERT_HEADER; @@ -1067,9 +1067,9 @@ ServerDHParams::ServerDHParams() ServerDHParams::~ServerDHParams() { - delete[] Ys_; - delete[] g_; - delete[] p_; + ysArrayDelete(Ys_); + ysArrayDelete(g_); + ysArrayDelete(p_); } @@ -1111,21 +1111,21 @@ const opaque* ServerDHParams::get_pub() const opaque* ServerDHParams::alloc_p(int sz) { - p_ = new opaque[pSz_ = sz]; + p_ = new (ys) opaque[pSz_ = sz]; return p_; } opaque* ServerDHParams::alloc_g(int sz) { - g_ = new opaque[gSz_ = sz]; + g_ = new (ys) opaque[gSz_ = sz]; return g_; } opaque* ServerDHParams::alloc_pub(int sz) { - Ys_ = new opaque[pubSz_ = sz]; + Ys_ = new (ys) opaque[pubSz_ = sz]; return Ys_; } @@ -1466,7 +1466,7 @@ ServerKeyExchange::ServerKeyExchange() ServerKeyExchange::~ServerKeyExchange() { - delete server_key_; + ysDelete(server_key_); } @@ -1537,7 +1537,7 @@ void CertificateRequest::Build() for (int j = 0; j < authCount; j++) { int sz = REQUEST_HEADER + MIN_DIS_SIZE; DistinguishedName dn; - certificate_authorities_.push_back(dn = new byte[sz]); + certificate_authorities_.push_back(dn = new (ys) byte[sz]); opaque tmp[REQUEST_HEADER]; c16toa(MIN_DIS_SIZE, tmp); @@ -1584,7 +1584,7 @@ input_buffer& operator>>(input_buffer& input, CertificateRequest& request) ato16(tmp, dnSz); DistinguishedName dn; - request.certificate_authorities_.push_back(dn = new + request.certificate_authorities_.push_back(dn = new (ys) byte[REQUEST_HEADER + dnSz]); memcpy(dn, tmp, REQUEST_HEADER); input.read(&dn[REQUEST_HEADER], dnSz); @@ -1647,7 +1647,7 @@ CertificateVerify::CertificateVerify() : signature_(0) CertificateVerify::~CertificateVerify() { - delete[] signature_; + ysArrayDelete(signature_); } @@ -1657,7 +1657,7 @@ void CertificateVerify::Build(SSL& ssl) uint16 sz = 0; byte len[VERIFY_HEADER]; - mySTL::auto_ptr sig; + mySTL::auto_ptr sig(ysArrayDelete); // sign const CertManager& cert = ssl.getCrypto().get_certManager(); @@ -1665,7 +1665,7 @@ void CertificateVerify::Build(SSL& ssl) RSA rsa(cert.get_privateKey(), cert.get_privateKeyLength(), false); sz = rsa.get_cipherLength() + VERIFY_HEADER; - sig.reset(new byte[sz]); + sig.reset(new (ys) byte[sz]); c16toa(sz - VERIFY_HEADER, len); memcpy(sig.get(), len, VERIFY_HEADER); @@ -1676,7 +1676,7 @@ void CertificateVerify::Build(SSL& ssl) DSS dss(cert.get_privateKey(), cert.get_privateKeyLength(), false); sz = DSS_SIG_SZ + DSS_ENCODED_EXTRA + VERIFY_HEADER; - sig.reset(new byte[sz]); + sig.reset(new (ys) byte[sz]); c16toa(sz - VERIFY_HEADER, len); memcpy(sig.get(), len, VERIFY_HEADER); @@ -1714,7 +1714,7 @@ input_buffer& operator>>(input_buffer& input, CertificateVerify& request) ato16(tmp, sz); request.set_length(sz); - request.signature_ = new byte[sz]; + request.signature_ = new (ys) byte[sz]; input.read(request.signature_, sz); return input; @@ -1796,7 +1796,7 @@ ClientKeyExchange::ClientKeyExchange() ClientKeyExchange::~ClientKeyExchange() { - delete client_key_; + ysDelete(client_key_); } @@ -1969,13 +1969,13 @@ Connection::Connection(ProtocolVersion v, RandomPool& ran) Connection::~Connection() { - CleanMaster(); CleanPreMaster(); delete[] pre_master_secret_; + CleanMaster(); CleanPreMaster(); ysArrayDelete(pre_master_secret_); } void Connection::AllocPreSecret(uint sz) { - pre_master_secret_ = new opaque[pre_secret_len_ = sz]; + pre_master_secret_ = new (ys) opaque[pre_secret_len_ = sz]; } @@ -2004,42 +2004,42 @@ void Connection::CleanPreMaster() volatile opaque* p = pre_master_secret_; clean(p, pre_secret_len_, random_); - delete[] pre_master_secret_; + ysArrayDelete(pre_master_secret_); pre_master_secret_ = 0; } } // Create functions for message factory -Message* CreateCipherSpec() { return new ChangeCipherSpec; } -Message* CreateAlert() { return new Alert; } -Message* CreateHandShake() { return new HandShakeHeader; } -Message* CreateData() { return new Data; } +Message* CreateCipherSpec() { return new (ys) ChangeCipherSpec; } +Message* CreateAlert() { return new (ys) Alert; } +Message* CreateHandShake() { return new (ys) HandShakeHeader; } +Message* CreateData() { return new (ys) Data; } // Create functions for handshake factory -HandShakeBase* CreateHelloRequest() { return new HelloRequest; } -HandShakeBase* CreateClientHello() { return new ClientHello; } -HandShakeBase* CreateServerHello() { return new ServerHello; } -HandShakeBase* CreateCertificate() { return new Certificate; } -HandShakeBase* CreateServerKeyExchange() { return new ServerKeyExchange;} -HandShakeBase* CreateCertificateRequest() { return new +HandShakeBase* CreateHelloRequest() { return new (ys) HelloRequest; } +HandShakeBase* CreateClientHello() { return new (ys) ClientHello; } +HandShakeBase* CreateServerHello() { return new (ys) ServerHello; } +HandShakeBase* CreateCertificate() { return new (ys) Certificate; } +HandShakeBase* CreateServerKeyExchange() { return new (ys) ServerKeyExchange;} +HandShakeBase* CreateCertificateRequest() { return new (ys) CertificateRequest; } -HandShakeBase* CreateServerHelloDone() { return new ServerHelloDone; } -HandShakeBase* CreateCertificateVerify() { return new CertificateVerify;} -HandShakeBase* CreateClientKeyExchange() { return new ClientKeyExchange;} -HandShakeBase* CreateFinished() { return new Finished; } +HandShakeBase* CreateServerHelloDone() { return new (ys) ServerHelloDone; } +HandShakeBase* CreateCertificateVerify() { return new (ys) CertificateVerify;} +HandShakeBase* CreateClientKeyExchange() { return new (ys) ClientKeyExchange;} +HandShakeBase* CreateFinished() { return new (ys) Finished; } // Create functions for server key exchange factory -ServerKeyBase* CreateRSAServerKEA() { return new RSA_Server; } -ServerKeyBase* CreateDHServerKEA() { return new DH_Server; } -ServerKeyBase* CreateFortezzaServerKEA() { return new Fortezza_Server; } +ServerKeyBase* CreateRSAServerKEA() { return new (ys) RSA_Server; } +ServerKeyBase* CreateDHServerKEA() { return new (ys) DH_Server; } +ServerKeyBase* CreateFortezzaServerKEA() { return new (ys) Fortezza_Server; } // Create functions for client key exchange factory -ClientKeyBase* CreateRSAClient() { return new +ClientKeyBase* CreateRSAClient() { return new (ys) EncryptedPreMasterSecret; } -ClientKeyBase* CreateDHClient() { return new +ClientKeyBase* CreateDHClient() { return new (ys) ClientDiffieHellmanPublic; } -ClientKeyBase* CreateFortezzaClient() { return new FortezzaKeys; } +ClientKeyBase* CreateFortezzaClient() { return new (ys) FortezzaKeys; } // Constructor calls this to Register compile time callbacks @@ -2089,29 +2089,5 @@ void InitClientKeyFactory(ClientKeyFactory& ckf) ckf.Register(fortezza_kea, CreateFortezzaClient); } -} // namespace -#ifdef __GNUC__ -namespace mySTL { -template class mySTL::list; -template yaSSL::del_ptr_zero mySTL::for_each(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); -template mySTL::pair* mySTL::uninit_copy*, mySTL::pair*>(mySTL::pair*, mySTL::pair*, mySTL::pair*); -template mySTL::pair* mySTL::uninit_copy*, mySTL::pair*>(mySTL::pair*, mySTL::pair*, mySTL::pair*); -template void mySTL::destroy*>(mySTL::pair*, mySTL::pair*); -template void mySTL::destroy*>(mySTL::pair*, mySTL::pair*); -template mySTL::pair* mySTL::uninit_copy*, mySTL::pair*>(mySTL::pair*, mySTL::pair*, mySTL::pair*); -template void mySTL::destroy*>(mySTL::pair*, mySTL::pair*); -template mySTL::pair* mySTL::uninit_copy*, mySTL::pair*>(mySTL::pair*, mySTL::pair*, mySTL::pair*); -template class mySTL::list; -template class mySTL::list; -template class mySTL::list; -template class mySTL::list; -template class mySTL::list; -template void mySTL::destroy*>(mySTL::pair*, mySTL::pair*); -template yaSSL::del_ptr_zero mySTL::for_each::iterator, yaSSL::del_ptr_zero>(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); -template yaSSL::del_ptr_zero mySTL::for_each::iterator, yaSSL::del_ptr_zero>(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); -template yaSSL::del_ptr_zero mySTL::for_each::iterator, yaSSL::del_ptr_zero>(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); -template yaSSL::del_ptr_zero mySTL::for_each::iterator, yaSSL::del_ptr_zero>(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); -template yaSSL::del_ptr_zero mySTL::for_each::iterator, yaSSL::del_ptr_zero>(mySTL::list::iterator, mySTL::list::iterator, yaSSL::del_ptr_zero); -} -#endif +} // namespace diff --git a/extra/yassl/src/yassl_int.cpp b/extra/yassl/src/yassl_int.cpp index 718871a598b..06be7a15503 100644 --- a/extra/yassl/src/yassl_int.cpp +++ b/extra/yassl/src/yassl_int.cpp @@ -24,19 +24,47 @@ * draft along with type conversion functions. */ -#include "runtime.hpp" #include "yassl_int.hpp" #include "handshake.hpp" #include "timer.hpp" #include "openssl/ssl.h" // for DH +void* operator new(size_t sz, yaSSL::new_t) +{ + void* ptr = malloc(sz ? sz : 1); + if (!ptr) abort(); + + return ptr; +} + +void* operator new[](size_t sz, yaSSL::new_t) +{ + void* ptr = malloc(sz ? sz : 1); + if (!ptr) abort(); + + return ptr; +} + +void operator delete(void* ptr, yaSSL::new_t) +{ + if (ptr) free(ptr); +} + +void operator delete[](void* ptr, yaSSL::new_t) +{ + if (ptr) free(ptr); +} + + namespace yaSSL { using mySTL::min; +new_t ys; // for yaSSL library new + // convert a 32 bit integer into a 24 bit one @@ -284,8 +312,8 @@ void SSL::set_pending(Cipher suite) parms.key_size_ = AES_256_KEY_SZ; parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; - crypto_.setDigest(new SHA); - crypto_.setCipher(new AES(AES_256_KEY_SZ)); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME); break; @@ -298,8 +326,8 @@ void SSL::set_pending(Cipher suite) parms.key_size_ = AES_128_KEY_SZ; parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; - crypto_.setDigest(new SHA); - crypto_.setCipher(new AES); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) AES); strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME); break; @@ -312,8 +340,8 @@ void SSL::set_pending(Cipher suite) parms.key_size_ = DES_EDE_KEY_SZ; parms.iv_size_ = DES_IV_SZ; parms.cipher_type_ = block; - crypto_.setDigest(new SHA); - crypto_.setCipher(new DES_EDE); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) DES_EDE); strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_3DES_EDE_CBC_SHA] , MAX_SUITE_NAME); break; @@ -326,8 +354,8 @@ void SSL::set_pending(Cipher suite) parms.key_size_ = DES_KEY_SZ; parms.iv_size_ = DES_IV_SZ; parms.cipher_type_ = block; - crypto_.setDigest(new SHA); - crypto_.setCipher(new DES); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) DES); strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_DES_CBC_SHA], MAX_SUITE_NAME); break; @@ -340,8 +368,8 @@ void SSL::set_pending(Cipher suite) parms.key_size_ = RC4_KEY_SZ; parms.iv_size_ = 0; parms.cipher_type_ = stream; - crypto_.setDigest(new SHA); - crypto_.setCipher(new RC4); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) RC4); strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_RC4_128_SHA], MAX_SUITE_NAME); break; @@ -354,8 +382,8 @@ void SSL::set_pending(Cipher suite) parms.key_size_ = RC4_KEY_SZ; parms.iv_size_ = 0; parms.cipher_type_ = stream; - crypto_.setDigest(new MD5); - crypto_.setCipher(new RC4); + crypto_.setDigest(new (ys) MD5); + crypto_.setCipher(new (ys) RC4); strncpy(parms.cipher_name_, cipher_names[SSL_RSA_WITH_RC4_128_MD5], MAX_SUITE_NAME); break; @@ -370,8 +398,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = DES_IV_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new SHA); - crypto_.setCipher(new DES); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) DES); strncpy(parms.cipher_name_, cipher_names[SSL_DHE_RSA_WITH_DES_CBC_SHA], MAX_SUITE_NAME); break; @@ -386,8 +414,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = DES_IV_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new SHA); - crypto_.setCipher(new DES_EDE); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) DES_EDE); strncpy(parms.cipher_name_, cipher_names[SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA], MAX_SUITE_NAME); break; @@ -402,8 +430,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new SHA); - crypto_.setCipher(new AES(AES_256_KEY_SZ)); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); strncpy(parms.cipher_name_, cipher_names[TLS_DHE_RSA_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME); break; @@ -418,8 +446,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new SHA); - crypto_.setCipher(new AES); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) AES); strncpy(parms.cipher_name_, cipher_names[TLS_DHE_RSA_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME); break; @@ -434,8 +462,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = DES_IV_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new SHA); - crypto_.setCipher(new DES); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) DES); strncpy(parms.cipher_name_, cipher_names[SSL_DHE_DSS_WITH_DES_CBC_SHA], MAX_SUITE_NAME); break; @@ -450,8 +478,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = DES_IV_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new SHA); - crypto_.setCipher(new DES_EDE); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) DES_EDE); strncpy(parms.cipher_name_, cipher_names[SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA], MAX_SUITE_NAME); break; @@ -466,8 +494,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new SHA); - crypto_.setCipher(new AES(AES_256_KEY_SZ)); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); strncpy(parms.cipher_name_, cipher_names[TLS_DHE_DSS_WITH_AES_256_CBC_SHA], MAX_SUITE_NAME); break; @@ -482,8 +510,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new SHA); - crypto_.setCipher(new AES); + crypto_.setDigest(new (ys) SHA); + crypto_.setCipher(new (ys) AES); strncpy(parms.cipher_name_, cipher_names[TLS_DHE_DSS_WITH_AES_128_CBC_SHA], MAX_SUITE_NAME); break; @@ -496,8 +524,8 @@ void SSL::set_pending(Cipher suite) parms.key_size_ = AES_256_KEY_SZ; parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; - crypto_.setDigest(new RMD); - crypto_.setCipher(new AES(AES_256_KEY_SZ)); + crypto_.setDigest(new (ys) RMD); + crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_256_CBC_RMD160], MAX_SUITE_NAME); break; @@ -510,8 +538,8 @@ void SSL::set_pending(Cipher suite) parms.key_size_ = AES_128_KEY_SZ; parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; - crypto_.setDigest(new RMD); - crypto_.setCipher(new AES); + crypto_.setDigest(new (ys) RMD); + crypto_.setCipher(new (ys) AES); strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_AES_128_CBC_RMD160], MAX_SUITE_NAME); break; @@ -524,8 +552,8 @@ void SSL::set_pending(Cipher suite) parms.key_size_ = DES_EDE_KEY_SZ; parms.iv_size_ = DES_IV_SZ; parms.cipher_type_ = block; - crypto_.setDigest(new RMD); - crypto_.setCipher(new DES_EDE); + crypto_.setDigest(new (ys) RMD); + crypto_.setCipher(new (ys) DES_EDE); strncpy(parms.cipher_name_, cipher_names[TLS_RSA_WITH_3DES_EDE_CBC_RMD160], MAX_SUITE_NAME); break; @@ -540,8 +568,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = DES_IV_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new RMD); - crypto_.setCipher(new DES_EDE); + crypto_.setDigest(new (ys) RMD); + crypto_.setCipher(new (ys) DES_EDE); strncpy(parms.cipher_name_, cipher_names[TLS_DHE_RSA_WITH_3DES_EDE_CBC_RMD160], MAX_SUITE_NAME); @@ -557,8 +585,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new RMD); - crypto_.setCipher(new AES(AES_256_KEY_SZ)); + crypto_.setDigest(new (ys) RMD); + crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); strncpy(parms.cipher_name_, cipher_names[TLS_DHE_RSA_WITH_AES_256_CBC_RMD160], MAX_SUITE_NAME); @@ -574,8 +602,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new RMD); - crypto_.setCipher(new AES); + crypto_.setDigest(new (ys) RMD); + crypto_.setCipher(new (ys) AES); strncpy(parms.cipher_name_, cipher_names[TLS_DHE_RSA_WITH_AES_128_CBC_RMD160], MAX_SUITE_NAME); @@ -591,8 +619,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = DES_IV_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new RMD); - crypto_.setCipher(new DES_EDE); + crypto_.setDigest(new (ys) RMD); + crypto_.setCipher(new (ys) DES_EDE); strncpy(parms.cipher_name_, cipher_names[TLS_DHE_DSS_WITH_3DES_EDE_CBC_RMD160], MAX_SUITE_NAME); @@ -608,8 +636,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new RMD); - crypto_.setCipher(new AES(AES_256_KEY_SZ)); + crypto_.setDigest(new (ys) RMD); + crypto_.setCipher(new (ys) AES(AES_256_KEY_SZ)); strncpy(parms.cipher_name_, cipher_names[TLS_DHE_DSS_WITH_AES_256_CBC_RMD160], MAX_SUITE_NAME); @@ -625,8 +653,8 @@ void SSL::set_pending(Cipher suite) parms.iv_size_ = AES_BLOCK_SZ; parms.cipher_type_ = block; secure_.use_connection().send_server_key_ = true; // eph - crypto_.setDigest(new RMD); - crypto_.setCipher(new AES); + crypto_.setDigest(new (ys) RMD); + crypto_.setCipher(new (ys) AES); strncpy(parms.cipher_name_, cipher_names[TLS_DHE_DSS_WITH_AES_128_CBC_RMD160], MAX_SUITE_NAME); @@ -940,7 +968,7 @@ void SSL::fillData(Data& data) if (readSz == frontSz) { buffers_.useData().pop_front(); - delete front; + ysDelete(front); } if (data.get_length() == dataSz) break; @@ -964,7 +992,7 @@ void SSL::flushBuffer() out.write(front->get_buffer(), front->get_size()); buffers_.useHandShake().pop_front(); - delete front; + ysDelete(front); } Send(out.get_buffer(), out.get_size()); } @@ -1346,7 +1374,7 @@ typedef Mutex::Lock Lock; void Sessions::add(const SSL& ssl) { Lock guard(mutex_); - list_.push_back(new SSL_SESSION(ssl, random_)); + list_.push_back(new (ys) SSL_SESSION(ssl, random_)); } @@ -1459,9 +1487,9 @@ SSL_CTX::SSL_CTX(SSL_METHOD* meth) SSL_CTX::~SSL_CTX() { - delete method_; - delete certificate_; - delete privateKey_; + ysDelete(method_); + ysDelete(certificate_); + ysDelete(privateKey_); mySTL::for_each(caList_.begin(), caList_.end(), del_ptr_zero()); } @@ -1667,9 +1695,9 @@ Crypto::Crypto() Crypto::~Crypto() { - delete dh_; - delete cipher_; - delete digest_; + ysDelete(dh_); + ysDelete(cipher_); + ysDelete(digest_); } @@ -1744,7 +1772,7 @@ void Crypto::SetDH(DiffieHellman* dh) void Crypto::SetDH(const DH_Parms& dh) { if (dh.set_) - dh_ = new DiffieHellman(dh.p_, dh.g_, random_); + dh_ = new (ys) DiffieHellman(dh.p_, dh.g_, random_); } @@ -1911,7 +1939,7 @@ X509_NAME::X509_NAME(const char* n, size_t sz) : name_(0) { if (sz) { - name_ = new char[sz]; + name_ = new (ys) char[sz]; memcpy(name_, n, sz); } } @@ -1919,7 +1947,7 @@ X509_NAME::X509_NAME(const char* n, size_t sz) X509_NAME::~X509_NAME() { - delete[] name_; + ysArrayDelete(name_); } diff --git a/extra/yassl/taocrypt/include/algebra.hpp b/extra/yassl/taocrypt/include/algebra.hpp index 92cac607d97..a09ac8dce16 100644 --- a/extra/yassl/taocrypt/include/algebra.hpp +++ b/extra/yassl/taocrypt/include/algebra.hpp @@ -38,7 +38,7 @@ namespace TaoCrypt { // abcd = group.Add(a, group.Add(b, group.Add(c,d)); // Abstract Group -class TAOCRYPT_NO_VTABLE AbstractGroup +class TAOCRYPT_NO_VTABLE AbstractGroup : public virtual_base { public: typedef Integer Element; @@ -70,8 +70,8 @@ class TAOCRYPT_NO_VTABLE AbstractRing : public AbstractGroup public: typedef Integer Element; - AbstractRing() {m_mg.m_pRing = this;} - AbstractRing(const AbstractRing &source) : AbstractGroup() {m_mg.m_pRing = this;} + AbstractRing() : AbstractGroup() {m_mg.m_pRing = this;} + AbstractRing(const AbstractRing &source) {m_mg.m_pRing = this;} AbstractRing& operator=(const AbstractRing &source) {return *this;} virtual bool IsUnit(const Element &a) const =0; diff --git a/extra/yassl/taocrypt/include/asn.hpp b/extra/yassl/taocrypt/include/asn.hpp index 974bbf4c86f..14fcf22d843 100644 --- a/extra/yassl/taocrypt/include/asn.hpp +++ b/extra/yassl/taocrypt/include/asn.hpp @@ -106,7 +106,7 @@ class DH; // General BER decoding -class BER_Decoder { +class BER_Decoder : public virtual_base { protected: Source& source_; public: @@ -184,7 +184,7 @@ class PublicKey { word32 sz_; public: explicit PublicKey(const byte* k = 0, word32 s = 0); - ~PublicKey() { delete[] key_; } + ~PublicKey() { tcArrayDelete(key_); } const byte* GetKey() const { return key_; } word32 size() const { return sz_; } @@ -287,7 +287,7 @@ word32 DecodeDSA_Signature(byte* decoded, const byte* encoded, word32 sz); // General DER encoding -class DER_Encoder { +class DER_Encoder : public virtual_base { public: DER_Encoder() {} virtual ~DER_Encoder() {} diff --git a/extra/yassl/taocrypt/include/block.hpp b/extra/yassl/taocrypt/include/block.hpp index f3c4415682d..c5eec55d37e 100644 --- a/extra/yassl/taocrypt/include/block.hpp +++ b/extra/yassl/taocrypt/include/block.hpp @@ -100,13 +100,13 @@ public: CheckSize(n); if (n == 0) return 0; - return new T[n]; + return new (tc) T[n]; } void deallocate(void* p, size_type n) { memset(p, 0, n * sizeof(T)); - delete [] (T*)p; + tcArrayDelete((T*)p); } pointer reallocate(T* p, size_type oldSize, size_type newSize, diff --git a/extra/yassl/taocrypt/include/hash.hpp b/extra/yassl/taocrypt/include/hash.hpp index f01f343c2d1..257aa1be419 100644 --- a/extra/yassl/taocrypt/include/hash.hpp +++ b/extra/yassl/taocrypt/include/hash.hpp @@ -32,7 +32,7 @@ namespace TaoCrypt { // HASH -class HASH { +class HASH : public virtual_base { public: virtual ~HASH() {} @@ -50,9 +50,9 @@ public: class HASHwithTransform : public HASH { public: HASHwithTransform(word32 digSz, word32 buffSz) - : digest_(new word32[digSz]), buffer_(new byte[buffSz]) {} - virtual ~HASHwithTransform() { delete[] buffer_; delete[] digest_; } - + : digest_(new (tc) word32[digSz]), buffer_(new (tc) byte[buffSz]) {} + virtual ~HASHwithTransform() { tcArrayDelete(buffer_); + tcArrayDelete(digest_); } virtual ByteOrder getByteOrder() const = 0; virtual word32 getPadSize() const = 0; diff --git a/extra/yassl/taocrypt/include/integer.hpp b/extra/yassl/taocrypt/include/integer.hpp index e9e4a7218bd..f9ef267ce4c 100644 --- a/extra/yassl/taocrypt/include/integer.hpp +++ b/extra/yassl/taocrypt/include/integer.hpp @@ -136,9 +136,8 @@ public: ~Integer() {} - static const Integer &Zero(); - static const Integer &One(); - static const Integer &Two(); + static const Integer& Zero(); + static const Integer& One(); Integer& Ref() { return *this; } @@ -252,9 +251,6 @@ private: friend class ModularArithmetic; friend class MontgomeryRepresentation; - static const Integer zero; - static const Integer one; - static const Integer two; Integer(word value, unsigned int length); int PositiveCompare(const Integer& t) const; @@ -267,6 +263,9 @@ private: Integer& dividend, const Integer& divisor); AlignedWordBlock reg_; Sign sign_; + + static const Integer zero_; + static const Integer one_; }; inline bool operator==(const Integer& a, const Integer& b) diff --git a/extra/yassl/taocrypt/include/misc.hpp b/extra/yassl/taocrypt/include/misc.hpp index de8cbb30fcb..812cdd93879 100644 --- a/extra/yassl/taocrypt/include/misc.hpp +++ b/extra/yassl/taocrypt/include/misc.hpp @@ -27,75 +27,59 @@ #include #include #include +#include "types.hpp" +#include "type_traits.hpp" + +/* +namespace GCC_ABI { + extern "C" int __cxa_pure_virtual(); +} */ + +namespace TaoCrypt { + +// using GCC_ABI::__cxa_pure_virtual; + +// library allocation +struct new_t {}; // TaoCrypt New type +extern new_t tc; // pass in parameter + +} // namespace TaoCrypt + +void* operator new (size_t, TaoCrypt::new_t); +void* operator new[](size_t, TaoCrypt::new_t); + +void operator delete (void*, TaoCrypt::new_t); +void operator delete[](void*, TaoCrypt::new_t); namespace TaoCrypt { +template +void tcDelete(T* ptr) +{ + if (ptr) ptr->~T(); + ::operator delete(ptr, TaoCrypt::tc); +} -// define this if running on a big-endian CPU -#if !defined(LITTLE_ENDIAN_ORDER) && (defined(__BIG_ENDIAN__) || \ - defined(__sparc) || defined(__sparc__) || defined(__hppa__) || \ - defined(__mips__) || (defined(__MWERKS__) && !defined(__INTEL__))) - #define BIG_ENDIAN_ORDER -#endif +template +void tcArrayDelete(T* ptr) +{ + // can't do array placement destruction since not tracking size in + // allocation, only allow builtins to use array placement since they + // don't need destructors called + typedef char builtin[IsFundamentalType::Yes ? 1 : -1]; + (void)sizeof(builtin); -#ifndef BIG_ENDIAN_ORDER - #define LITTLE_ENDIAN_ORDER -#endif + ::operator delete[](ptr, TaoCrypt::tc); +} -typedef unsigned char byte; -typedef unsigned short word16; -typedef unsigned int word32; - -#if defined(__GNUC__) || defined(__MWERKS__) || defined(_LONGLONG_TYPE) - #define WORD64_AVAILABLE - typedef unsigned long long word64; - #define W64LIT(x) x##LL -#elif defined(_MSC_VER) || defined(__BCPLUSPLUS__) - #define WORD64_AVAILABLE - typedef unsigned __int64 word64; - #define W64LIT(x) x##ui64 -#elif defined(__DECCXX) - #define WORD64_AVAILABLE - typedef unsigned long word64; -#endif - -// define largest word type -#ifdef WORD64_AVAILABLE - typedef word64 lword; -#else - typedef word32 lword; -#endif - -// FIXME the !defined(__sun) is a temporarely solution until asm for -// __x86_64__ and Solaris is written -#if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \ - defined(__mips64) || (defined(__x86_64__) && !defined(__sun)) -// These platforms have 64-bit CPU registers. Unfortunately most C++ compilers -// don't allow any way to access the 64-bit by 64-bit multiply instruction -// without using assembly, so in order to use word64 as word, the assembly -// instruction must be defined in Dword::Multiply(). - typedef word32 hword; - typedef word64 word; -#else - #define TAOCRYPT_NATIVE_DWORD_AVAILABLE - #ifdef WORD64_AVAILABLE - #define TAOCRYPT_SLOW_WORD64 - // define this if your CPU is not64-bit to use alternative code - // that avoids word64 - typedef word16 hword; - typedef word32 word; - typedef word64 dword; - #else - typedef byte hword; - typedef word16 word; - typedef word32 dword; - #endif -#endif - -const word32 WORD_SIZE = sizeof(word); -const word32 WORD_BITS = WORD_SIZE * 8; +// to resolve compiler generated operator delete on base classes with +// virtual destructors, make sure doesn't get called +class virtual_base { +public: + static void operator delete(void*) { assert(0); } +}; #if defined(_MSC_VER) || defined(__BCPLUSPLUS__) diff --git a/extra/yassl/taocrypt/include/modes.hpp b/extra/yassl/taocrypt/include/modes.hpp index 3f9878a9e62..585231c9b9e 100644 --- a/extra/yassl/taocrypt/include/modes.hpp +++ b/extra/yassl/taocrypt/include/modes.hpp @@ -56,7 +56,7 @@ private: // Mode Base for block ciphers, static size -class Mode_BASE { +class Mode_BASE : public virtual_base { public: enum { MaxBlockSz = 16 }; diff --git a/extra/yassl/taocrypt/include/runtime.hpp b/extra/yassl/taocrypt/include/runtime.hpp index 43f1b72fd51..01106b6f960 100644 --- a/extra/yassl/taocrypt/include/runtime.hpp +++ b/extra/yassl/taocrypt/include/runtime.hpp @@ -31,30 +31,6 @@ #if __GNUC__ > 2 -#include - - -static void* operator new (size_t sz) -{ - return malloc (sz ? sz : 1); -} - -static void* operator new[](size_t sz) -{ - return malloc (sz ? sz : 1); -} - -static void operator delete (void* ptr) -{ - if (ptr) free(ptr); -} - -static void operator delete[] (void* ptr) -{ - if (ptr) free(ptr); -} - - extern "C" { #include diff --git a/extra/yassl/taocrypt/include/type_traits.hpp b/extra/yassl/taocrypt/include/type_traits.hpp new file mode 100644 index 00000000000..caf71f90e11 --- /dev/null +++ b/extra/yassl/taocrypt/include/type_traits.hpp @@ -0,0 +1,80 @@ +/* type_traits.hpp + * + * Copyright (C) 2003 Sawtooth Consulting Ltd. + * + * This file is part of yaSSL. + * + * yaSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * yaSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +/* type_traits defines fundamental types + * see discussion in C++ Templates, $19.1 +*/ + + +#ifndef TAO_CRYPT_TYPE_TRAITS_HPP +#define TAO_CRYPT_TYPE_TRAITS_HPP + +#include "types.hpp" + +namespace TaoCrypt { + + +// primary template: in general T is not a fundamental type + +template +class IsFundamentalType { + public: + enum { Yes = 0, No = 1 }; +}; + + +// macro to specialize for fundamental types +#define MK_FUNDAMENTAL_TYPE(T) \ + template<> class IsFundamentalType { \ + public: \ + enum { Yes = 1, No = 0 }; \ + }; + + +MK_FUNDAMENTAL_TYPE(void) + +MK_FUNDAMENTAL_TYPE(bool) +MK_FUNDAMENTAL_TYPE( char) +MK_FUNDAMENTAL_TYPE(signed char) +MK_FUNDAMENTAL_TYPE(unsigned char) + +MK_FUNDAMENTAL_TYPE(signed short) +MK_FUNDAMENTAL_TYPE(unsigned short) +MK_FUNDAMENTAL_TYPE(signed int) +MK_FUNDAMENTAL_TYPE(unsigned int) +MK_FUNDAMENTAL_TYPE(signed long) +MK_FUNDAMENTAL_TYPE(unsigned long) + +MK_FUNDAMENTAL_TYPE(float) +MK_FUNDAMENTAL_TYPE( double) +MK_FUNDAMENTAL_TYPE(long double) + +#ifdef WORD64_AVAILABLE + MK_FUNDAMENTAL_TYPE(word64) +#endif + + +#undef MK_FUNDAMENTAL_TYPE + + +} // namespace + +#endif // TAO_CRYPT_TYPE_TRAITS_HPP diff --git a/extra/yassl/taocrypt/include/types.hpp b/extra/yassl/taocrypt/include/types.hpp new file mode 100644 index 00000000000..0d57022a2d0 --- /dev/null +++ b/extra/yassl/taocrypt/include/types.hpp @@ -0,0 +1,99 @@ +/* types.hpp + * + * Copyright (C) 2003 Sawtooth Consulting Ltd. + * + * This file is part of yaSSL. + * + * yaSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * yaSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +/* based on Wei Dai's misc.h from CryptoPP, basic crypt types */ + + +#ifndef TAO_CRYPT_TYPES_HPP +#define TAO_CRYPT_TYPES_HPP + +namespace TaoCrypt { + +// define this if running on a big-endian CPU +#if !defined(LITTLE_ENDIAN_ORDER) && (defined(__BIG_ENDIAN__) || \ + defined(__sparc) || defined(__sparc__) || defined(__hppa__) || \ + defined(__mips__) || (defined(__MWERKS__) && !defined(__INTEL__))) + #define BIG_ENDIAN_ORDER +#endif + +#ifndef BIG_ENDIAN_ORDER + #define LITTLE_ENDIAN_ORDER +#endif + + +typedef unsigned char byte; +typedef unsigned short word16; +typedef unsigned int word32; + +#if defined(__GNUC__) || defined(__MWERKS__) || defined(_LONGLONG_TYPE) + #define WORD64_AVAILABLE + typedef unsigned long long word64; + #define W64LIT(x) x##LL +#elif defined(_MSC_VER) || defined(__BCPLUSPLUS__) + #define WORD64_AVAILABLE + typedef unsigned __int64 word64; + #define W64LIT(x) x##ui64 +#elif defined(__DECCXX) + #define WORD64_AVAILABLE + typedef unsigned long word64; +#endif + +// define largest word type +#ifdef WORD64_AVAILABLE + typedef word64 lword; +#else + typedef word32 lword; +#endif + + +// TODO: FIXME, add asm multiply for x86_64 on Solaris and remove !__sun + +#if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || \ + defined(__mips64) || (defined(__x86_64__) && !defined(__sun)) +// These platforms have 64-bit CPU registers. Unfortunately most C++ compilers +// don't allow any way to access the 64-bit by 64-bit multiply instruction +// without using assembly, so in order to use word64 as word, the assembly +// instruction must be defined in Dword::Multiply(). + typedef word32 hword; + typedef word64 word; +#else + #define TAOCRYPT_NATIVE_DWORD_AVAILABLE + #ifdef WORD64_AVAILABLE + #define TAOCRYPT_SLOW_WORD64 + // define this if your CPU is not64-bit to use alternative code + // that avoids word64 + typedef word16 hword; + typedef word32 word; + typedef word64 dword; + #else + typedef byte hword; + typedef word16 word; + typedef word32 dword; + #endif +#endif + +const word32 WORD_SIZE = sizeof(word); +const word32 WORD_BITS = WORD_SIZE * 8; + + +} // namespace + +#endif // TAO_CRYPT_TYPES_HPP diff --git a/extra/yassl/taocrypt/src/Makefile.am b/extra/yassl/taocrypt/src/Makefile.am index b00e6081c23..4005be94fb2 100644 --- a/extra/yassl/taocrypt/src/Makefile.am +++ b/extra/yassl/taocrypt/src/Makefile.am @@ -3,5 +3,6 @@ INCLUDES = -I../include -I../../mySTL noinst_LIBRARIES = libtaocrypt.a libtaocrypt_a_SOURCES = aes.cpp aestables.cpp algebra.cpp arc4.cpp asn.cpp \ coding.cpp dh.cpp des.cpp dsa.cpp file.cpp hash.cpp integer.cpp \ - md2.cpp md5.cpp misc.cpp random.cpp ripemd.cpp rsa.cpp sha.cpp + md2.cpp md5.cpp misc.cpp random.cpp ripemd.cpp rsa.cpp sha.cpp \ + template_instnt.cpp EXTRA_DIST = ../include/*.hpp diff --git a/extra/yassl/taocrypt/src/aestables.cpp b/extra/yassl/taocrypt/src/aestables.cpp index 7ba25bc9ffb..5a125dfd44d 100644 --- a/extra/yassl/taocrypt/src/aestables.cpp +++ b/extra/yassl/taocrypt/src/aestables.cpp @@ -21,7 +21,6 @@ /* based on Wei Dai's aestables.cpp from CryptoPP */ -#include "runtime.hpp" #include "aes.hpp" diff --git a/extra/yassl/taocrypt/src/algebra.cpp b/extra/yassl/taocrypt/src/algebra.cpp index d70f8dd5d72..7608e78b0ed 100644 --- a/extra/yassl/taocrypt/src/algebra.cpp +++ b/extra/yassl/taocrypt/src/algebra.cpp @@ -322,8 +322,6 @@ void AbstractRing::SimultaneousExponentiate(Integer *results, #ifdef __GNUC__ namespace mySTL { template TaoCrypt::WindowSlider* uninit_copy(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*); -template vector* uninit_fill_n*, unsigned int, vector >(vector*, unsigned int, vector const&); template void destroy(TaoCrypt::WindowSlider*, TaoCrypt::WindowSlider*); -template void destroy*>(vector*, vector*); } #endif diff --git a/extra/yassl/taocrypt/src/arc4.cpp b/extra/yassl/taocrypt/src/arc4.cpp index 1e521b48f0c..bbd77cd822c 100644 --- a/extra/yassl/taocrypt/src/arc4.cpp +++ b/extra/yassl/taocrypt/src/arc4.cpp @@ -21,7 +21,6 @@ /* based on Wei Dai's arc4.cpp from CryptoPP */ -#include "runtime.hpp" #include "arc4.hpp" diff --git a/extra/yassl/taocrypt/src/asn.cpp b/extra/yassl/taocrypt/src/asn.cpp index 59c544bd633..720fe7cd532 100644 --- a/extra/yassl/taocrypt/src/asn.cpp +++ b/extra/yassl/taocrypt/src/asn.cpp @@ -187,7 +187,7 @@ PublicKey::PublicKey(const byte* k, word32 s) : key_(0), sz_(0) void PublicKey::SetSize(word32 s) { sz_ = s; - key_ = new byte[sz_]; + key_ = new (tc) byte[sz_]; } @@ -199,14 +199,14 @@ void PublicKey::SetKey(const byte* k) void PublicKey::AddToEnd(const byte* data, word32 len) { - mySTL::auto_ptr tmp(new byte[sz_ + len]); + mySTL::auto_ptr tmp(new (tc) byte[sz_ + len], tcArrayDelete); memcpy(tmp.get(), key_, sz_); memcpy(tmp.get() + sz_, data, len); byte* del = 0; mySTL::swap(del, key_); - delete[] del; + tcArrayDelete(del); key_ = tmp.release(); sz_ += len; @@ -218,7 +218,7 @@ Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h) { if (n) { int sz = strlen(n); - name_ = new char[sz + 1]; + name_ = new (tc) char[sz + 1]; memcpy(name_, n, sz); name_[sz] = 0; } @@ -228,7 +228,7 @@ Signer::Signer(const byte* k, word32 kSz, const char* n, const byte* h) Signer::~Signer() { - delete[] name_; + tcArrayDelete(name_); } @@ -433,9 +433,9 @@ CertDecoder::CertDecoder(Source& s, bool decode, SignerList* signers) CertDecoder::~CertDecoder() { - delete[] subject_; - delete[] issuer_; - delete[] signature_; + tcArrayDelete(subject_); + tcArrayDelete(issuer_); + tcArrayDelete(signature_); } @@ -632,7 +632,7 @@ word32 CertDecoder::GetSignature() } sigLength_--; - signature_ = new byte[sigLength_]; + signature_ = new (tc) byte[sigLength_]; memcpy(signature_, source_.get_current(), sigLength_); source_.advance(sigLength_); @@ -653,7 +653,7 @@ word32 CertDecoder::GetDigest() sigLength_ = GetLength(source_); - signature_ = new byte[sigLength_]; + signature_ = new (tc) byte[sigLength_]; memcpy(signature_, source_.get_current(), sigLength_); source_.advance(sigLength_); @@ -693,7 +693,7 @@ void CertDecoder::GetName(NameType nt) if (id == COMMON_NAME) { char*& ptr = (nt == ISSUER) ? issuer_ : subject_; - ptr = new char[strLen + 1]; + ptr = new (tc) char[strLen + 1]; memcpy(ptr, source_.get_current(), strLen); ptr[strLen] = 0; } @@ -807,18 +807,18 @@ bool CertDecoder::ValidateSignature(SignerList* signers) bool CertDecoder::ConfirmSignature(Source& pub) { HashType ht; - mySTL::auto_ptr hasher; + mySTL::auto_ptr hasher(tcDelete); if (signatureOID_ == MD5wRSA) { - hasher.reset(new MD5); + hasher.reset(new (tc) MD5); ht = MD5h; } else if (signatureOID_ == MD2wRSA) { - hasher.reset(new MD2); + hasher.reset(new (tc) MD2); ht = MD2h; } else if (signatureOID_ == SHAwRSA || signatureOID_ == SHAwDSA) { - hasher.reset(new SHA); + hasher.reset(new (tc) SHA); ht = SHAh; } else { diff --git a/extra/yassl/taocrypt/src/coding.cpp b/extra/yassl/taocrypt/src/coding.cpp index 944a47c288e..6514ed4d46d 100644 --- a/extra/yassl/taocrypt/src/coding.cpp +++ b/extra/yassl/taocrypt/src/coding.cpp @@ -22,7 +22,6 @@ /* coding.cpp implements hex and base64 encoding/decoing */ -#include "runtime.hpp" #include "coding.hpp" #include "file.hpp" diff --git a/extra/yassl/taocrypt/src/dh.cpp b/extra/yassl/taocrypt/src/dh.cpp index ea1b5846f7d..d5f93f6c0f6 100644 --- a/extra/yassl/taocrypt/src/dh.cpp +++ b/extra/yassl/taocrypt/src/dh.cpp @@ -23,7 +23,6 @@ /* dh.cpp implements Diffie-Hellman support */ -#include "runtime.hpp" #include "dh.hpp" #include "asn.hpp" diff --git a/extra/yassl/taocrypt/src/dsa.cpp b/extra/yassl/taocrypt/src/dsa.cpp index 5cb3018a402..b89b42ac9d8 100644 --- a/extra/yassl/taocrypt/src/dsa.cpp +++ b/extra/yassl/taocrypt/src/dsa.cpp @@ -20,7 +20,6 @@ */ -#include "runtime.hpp" #include "dsa.hpp" #include "sha.hpp" #include "asn.hpp" diff --git a/extra/yassl/taocrypt/src/file.cpp b/extra/yassl/taocrypt/src/file.cpp index 4d48b9e7bca..75df80608ae 100644 --- a/extra/yassl/taocrypt/src/file.cpp +++ b/extra/yassl/taocrypt/src/file.cpp @@ -22,7 +22,6 @@ /* file.cpp implements File Sources and Sinks */ -#include "runtime.hpp" #include "file.hpp" diff --git a/extra/yassl/taocrypt/src/integer.cpp b/extra/yassl/taocrypt/src/integer.cpp index b6a1b72a41f..67f3c963cac 100644 --- a/extra/yassl/taocrypt/src/integer.cpp +++ b/extra/yassl/taocrypt/src/integer.cpp @@ -32,7 +32,6 @@ # pragma warning(disable: 4250 4660 4661 4786 4355) #endif -#include "runtime.hpp" #include "integer.hpp" #include "modarith.hpp" #include "asn.hpp" @@ -108,7 +107,7 @@ CPP_TYPENAME AllocatorBase::pointer AlignedAllocator::allocate( assert(IsAlignedOn(p, 16)); return (T*)p; } - return new T[n]; + return new (tc) T[n]; } @@ -129,7 +128,7 @@ void AlignedAllocator::deallocate(void* p, size_type n) #endif } else - delete [] (T *)p; + tcArrayDelete((T *)p); } #endif // SSE2 @@ -2691,25 +2690,19 @@ unsigned int Integer::Encode(byte* output, unsigned int outputLen, } -const Integer Integer::zero(1,2); +const Integer Integer::zero_; const Integer &Integer::Zero() { - return zero; + return zero_; } -const Integer Integer::one(1,2); + +const Integer Integer::one_(1,2); const Integer &Integer::One() { - return one; -} - -const Integer Integer::two(1,2); - -const Integer &Integer::Two() -{ - return two; + return one_; } @@ -3948,9 +3941,6 @@ Integer CRT(const Integer &xp, const Integer &p, const Integer &xq, #ifdef __GNUC__ template unsigned int DivideThreeWordsByTwo(unsigned int*, unsigned int, unsigned int, DWord*); -#if defined(SSE2_INTRINSICS_AVAILABLE) -template AlignedAllocator::pointer StdReallocate >(AlignedAllocator&, unsigned int*, AlignedAllocator::size_type, AlignedAllocator::size_type, bool); -#endif #endif } // namespace diff --git a/extra/yassl/taocrypt/src/misc.cpp b/extra/yassl/taocrypt/src/misc.cpp index 37d1bd1b14d..1780b3050e9 100644 --- a/extra/yassl/taocrypt/src/misc.cpp +++ b/extra/yassl/taocrypt/src/misc.cpp @@ -22,14 +22,73 @@ /* based on Wei Dai's misc.cpp from CryptoPP */ -#include "runtime.hpp" #include "misc.hpp" #include // for NewHandler +void* operator new(size_t sz, TaoCrypt::new_t) +{ + void* ptr = malloc(sz ? sz : 1); + if (!ptr) abort(); + + return ptr; +} + +void* operator new[](size_t sz, TaoCrypt::new_t) +{ + void* ptr = malloc(sz ? sz : 1); + if (!ptr) abort(); + + return ptr; +} + +void operator delete(void* ptr, TaoCrypt::new_t) +{ + if (ptr) free(ptr); +} + +void operator delete[](void* ptr, TaoCrypt::new_t) +{ + if (ptr) free(ptr); +} + + +/* uncomment to test +// make sure not using globals anywhere by forgetting to use overloaded +void* operator new(size_t sz) +{ + assert(0); + return malloc(sz); +} + +void operator delete(void* ptr) +{ + assert(0); +} + +void* operator new[](size_t sz) +{ + assert(0); + return malloc(sz); +} + +void operator delete[](void* ptr) +{ + assert(0); +} +*/ + +/* namespace GCC_ABI { + extern "C" int __cxa_pure_virtual() { assert(0); return 0; } +} */ + + namespace TaoCrypt { +new_t tc; // for library new + + inline void XorWords(word* r, const word* a, unsigned int n) { for (unsigned int i=0; i::pointer StdReallocate >(AllocatorWithCleanup&, unsigned char*, AllocatorWithCleanup::size_type, AllocatorWithCleanup::size_type, bool); -template AllocatorWithCleanup::pointer StdReallocate >(AllocatorWithCleanup&, unsigned int*, AllocatorWithCleanup::size_type, AllocatorWithCleanup::size_type, bool); -template class RSA_Decryptor; -template class RSA_Encryptor; -template class RSA_Encryptor; -#endif } // namespace - -#ifdef __GNUC__ -namespace mySTL { -template TaoCrypt::Integer* uninit_copy(TaoCrypt::Integer*, TaoCrypt::Integer*, TaoCrypt::Integer*); -template TaoCrypt::Integer* uninit_fill_n(TaoCrypt::Integer*, unsigned int, TaoCrypt::Integer const&); -template void destroy(TaoCrypt::Integer*, TaoCrypt::Integer*); -} -#endif - - diff --git a/extra/yassl/taocrypt/src/template_instnt.cpp b/extra/yassl/taocrypt/src/template_instnt.cpp new file mode 100644 index 00000000000..28dbdc5c739 --- /dev/null +++ b/extra/yassl/taocrypt/src/template_instnt.cpp @@ -0,0 +1,31 @@ +#include "integer.hpp" +#include "rsa.hpp" +#include "algebra.hpp" +#include "vector.hpp" +#include "hash.hpp" + +#ifdef __GNUC__ +namespace TaoCrypt { +#if defined(SSE2_INTRINSICS_AVAILABLE) +template AlignedAllocator::pointer StdReallocate >(AlignedAllocator&, unsigned int*, AlignedAllocator::size_type, AlignedAllocator::size_type, bool); +#endif +template AllocatorWithCleanup::pointer StdReallocate >(AllocatorWithCleanup&, unsigned char*, AllocatorWithCleanup::size_type, AllocatorWithCleanup::size_type, bool); +template AllocatorWithCleanup::pointer StdReallocate >(AllocatorWithCleanup&, unsigned int*, AllocatorWithCleanup::size_type, AllocatorWithCleanup::size_type, bool); +template class RSA_Decryptor; +template class RSA_Encryptor; +template class RSA_Encryptor; +} + +namespace mySTL { +template vector* uninit_fill_n*, unsigned int, vector >(vector*, unsigned int, vector const&); +template void destroy*>(vector*, vector*); +template TaoCrypt::Integer* uninit_copy(TaoCrypt::Integer*, TaoCrypt::Integer*, TaoCrypt::Integer*); +template TaoCrypt::Integer* uninit_fill_n(TaoCrypt::Integer*, unsigned int, TaoCrypt::Integer const&); +template void destroy(TaoCrypt::Integer*, TaoCrypt::Integer*); +} + +template void TaoCrypt::tcDelete(TaoCrypt::HASH*); +template void TaoCrypt::tcArrayDelete(unsigned*); +template void TaoCrypt::tcArrayDelete(unsigned char*); +template void TaoCrypt::tcArrayDelete(char*); +#endif diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 34ccab9bcc5..ae09b8d730c 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -579,3 +579,21 @@ select * from t2; b 1 drop table t1,t2; +use test; +create table t1 (a int); +create table t1 select * from t1; +ERROR HY000: You can't specify target table 't1' for update in FROM clause +create table t2 union = (t1) select * from t1; +ERROR HY000: You can't specify target table 't1' for update in FROM clause +flush tables with read lock; +unlock tables; +drop table t1; +create table t1(column.name int); +ERROR 42000: Incorrect table name 'column' +create table t1(test.column.name int); +ERROR 42000: Incorrect table name 'column' +create table t1(xyz.t1.name int); +ERROR 42000: Incorrect database name 'xyz' +create table t1(t1.name int); +create table t2(test.t2.name int); +drop table t1,t2; diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index d4733e6dc7e..d9712a28788 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -471,3 +471,33 @@ insert into t2 values (); select * from t1; select * from t2; drop table t1,t2; + +# +# Bug#10224 - ANALYZE TABLE crashing with simultaneous +# CREATE ... SELECT statement. +# This tests two additional possible errors and a hang if +# an improper fix is present. +# +connection default; +use test; +create table t1 (a int); +--error 1093 +create table t1 select * from t1; +--error 1093 +create table t2 union = (t1) select * from t1; +flush tables with read lock; +unlock tables; +drop table t1; + +# +# Bug#10413: Invalid column name is not rejected +# +--error 1103 +create table t1(column.name int); +--error 1103 +create table t1(test.column.name int); +--error 1102 +create table t1(xyz.t1.name int); +create table t1(t1.name int); +create table t2(test.t2.name int); +drop table t1,t2; diff --git a/sql/lock.cc b/sql/lock.cc index fe6e85bd23c..01bc2fc303f 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -82,8 +82,24 @@ static int unlock_external(THD *thd, TABLE **table,uint count); static void print_lock_error(int error, const char *); -MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, - bool ignore_global_read_lock) +/* + Lock tables. + + SYNOPSIS + mysql_lock_tables() + thd The current thread. + tables An array of pointers to the tables to lock. + count The number of tables to lock. + flags Options: + MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK Ignore a global read lock + MYSQL_LOCK_IGNORE_FLUSH Ignore a flush tables. + + RETURN + A lock structure pointer on success. + NULL on error. +*/ + +MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, uint flags) { MYSQL_LOCK *sql_lock; TABLE *write_lock_used; @@ -94,7 +110,8 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, if (!(sql_lock = get_lock_data(thd,tables,count, 0,&write_lock_used))) break; - if (global_read_lock && write_lock_used && ! ignore_global_read_lock) + if (global_read_lock && write_lock_used && + ! (flags & MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK)) { /* Someone has issued LOCK ALL TABLES FOR READ and we want a write lock @@ -128,7 +145,7 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, thd->some_tables_deleted=1; // Try again sql_lock->lock_count=0; // Locks are alread freed } - else if (!thd->some_tables_deleted) + else if (!thd->some_tables_deleted || (flags & MYSQL_LOCK_IGNORE_FLUSH)) { thd->locked=0; break; @@ -950,48 +967,3 @@ bool make_global_read_lock_block_commit(THD *thd) } - -/* - Set protection against global read lock. - - SYNOPSIS - set_protect_against_global_read_lock() - void - - RETURN - FALSE OK, no global read lock exists. - TRUE Error, global read lock exists already. -*/ - -bool set_protect_against_global_read_lock(void) -{ - bool global_read_lock_exists; - - pthread_mutex_lock(&LOCK_open); - if (! (global_read_lock_exists= test(global_read_lock))) - protect_against_global_read_lock++; - pthread_mutex_unlock(&LOCK_open); - return global_read_lock_exists; -} - - -/* - Unset protection against global read lock. - - SYNOPSIS - unset_protect_against_global_read_lock() - void - - RETURN - void -*/ - -void unset_protect_against_global_read_lock(void) -{ - pthread_mutex_lock(&LOCK_open); - protect_against_global_read_lock--; - pthread_mutex_unlock(&LOCK_open); - pthread_cond_broadcast(&COND_refresh); -} - - diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 1ba153b2489..4b2bbb0dc88 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1169,8 +1169,11 @@ extern pthread_t signal_thread; extern struct st_VioSSLAcceptorFd * ssl_acceptor_fd; #endif /* HAVE_OPENSSL */ -MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count, - bool ignore_global_read_lock= FALSE); +MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count, uint flags); +/* mysql_lock_tables() flags bits */ +#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001 +#define MYSQL_LOCK_IGNORE_FLUSH 0x0002 + void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock); void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock); void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index d2d141de962..a07927547c6 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1384,7 +1384,7 @@ bool reopen_tables(THD *thd,bool get_locks,bool in_refresh) MYSQL_LOCK *lock; /* We should always get these locks */ thd->some_tables_deleted=0; - if ((lock=mysql_lock_tables(thd,tables,(uint) (tables_ptr-tables)))) + if ((lock= mysql_lock_tables(thd, tables, (uint) (tables_ptr - tables), 0))) { thd->locked_tables=mysql_lock_merge(thd->locked_tables,lock); } @@ -2022,7 +2022,7 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type) { DBUG_ASSERT(thd->lock == 0); // You must lock everything at once if ((table->reginfo.lock_type= lock_type) != TL_UNLOCK) - if (!(thd->lock=mysql_lock_tables(thd,&table_list->table,1))) + if (! (thd->lock= mysql_lock_tables(thd, &table_list->table, 1, 0))) table= 0; } } @@ -2237,7 +2237,7 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count) thd->options|= OPTION_TABLE_LOCK; } - if (!(thd->lock=mysql_lock_tables(thd,start, (uint) (ptr - start)))) + if (! (thd->lock= mysql_lock_tables(thd, start, (uint) (ptr - start), 0))) { if (thd->lex->requires_prelocking()) { diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index bb48b7ada77..1aa034ce61c 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -433,7 +433,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, protocol->send_fields(&list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF); HANDLER_TABLES_HACK(thd); - lock= mysql_lock_tables(thd, &tables->table, 1); + lock= mysql_lock_tables(thd, &tables->table, 1, 0); HANDLER_TABLES_HACK(thd); if (!lock) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index cbb842c3635..cd6cc0d4f11 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1224,10 +1224,13 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list) Avoid that a global read lock steps in while we are creating the new thread. It would block trying to open the table. Hence, the DI thread and this thread would wait until after the global - readlock is gone. If the read lock exists already, we leave with - no table and then switch to non-delayed insert. + readlock is gone. Since the insert thread needs to wait for a + global read lock anyway, we do it right now. Note that + wait_if_global_read_lock() sets a protection against a new + global read lock when it succeeds. This needs to be released by + start_waiting_global_read_lock(). */ - if (set_protect_against_global_read_lock()) + if (wait_if_global_read_lock(thd, 0, 1)) goto err; if (!(tmp=new delayed_insert())) { @@ -1269,7 +1272,11 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list) pthread_cond_wait(&tmp->cond_client,&tmp->mutex); } pthread_mutex_unlock(&tmp->mutex); - unset_protect_against_global_read_lock(); + /* + Release the protection against the global read lock and wake + everyone, who might want to set a global read lock. + */ + start_waiting_global_read_lock(thd); thd->proc_info="got old table"; if (tmp->thd.killed) { @@ -1305,7 +1312,11 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list) err1: thd->fatal_error(); - unset_protect_against_global_read_lock(); + /* + Release the protection against the global read lock and wake + everyone, who might want to set a global read lock. + */ + start_waiting_global_read_lock(thd); err: pthread_mutex_unlock(&LOCK_delayed_create); DBUG_RETURN(0); // Continue with normal insert @@ -1663,7 +1674,8 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg) handler will close the table and finish when the outstanding inserts are done. */ - if (! (thd->lock= mysql_lock_tables(thd, &di->table, 1, TRUE))) + if (! (thd->lock= mysql_lock_tables(thd, &di->table, 1, + MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK))) { /* Fatal error */ di->dead= 1; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 77afbfe12c6..bf25d49735b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2777,6 +2777,24 @@ mysql_execute_command(THD *thd) lex->create_info.default_table_charset= lex->create_info.table_charset; lex->create_info.table_charset= 0; } + /* + The create-select command will open and read-lock the select table + and then create, open and write-lock the new table. If a global + read lock steps in, we get a deadlock. The write lock waits for + the global read lock, while the global read lock waits for the + select table to be closed. So we wait until the global readlock is + gone before starting both steps. Note that + wait_if_global_read_lock() sets a protection against a new global + read lock when it succeeds. This needs to be released by + start_waiting_global_read_lock(). We protect the normal CREATE + TABLE in the same way. That way we avoid that a new table is + created during a gobal read lock. + */ + if (wait_if_global_read_lock(thd, 0, 1)) + { + res= -1; + goto unsent_create_error; + } if (select_lex->item_list.elements) // With select { select_result *result; @@ -2794,7 +2812,7 @@ mysql_execute_command(THD *thd) unique_table(create_table, select_tables)) { my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table->table_name); - goto unsent_create_error; + goto unsent_create_error1; } /* If we create merge table, we have to test tables in merge, too */ if (lex->create_info.used_fields & HA_CREATE_USED_UNION) @@ -2807,7 +2825,7 @@ mysql_execute_command(THD *thd) if (unique_table(tab, select_tables)) { my_error(ER_UPDATE_TABLE_USED, MYF(0), tab->table_name); - goto unsent_create_error; + goto unsent_create_error1; } } } @@ -2850,9 +2868,21 @@ mysql_execute_command(THD *thd) if (!res) send_ok(thd); } + /* + Release the protection against the global read lock and wake + everyone, who might want to set a global read lock. + */ + start_waiting_global_read_lock(thd); lex->link_first_table_back(create_table, link_to_local); break; +unsent_create_error1: + /* + Release the protection against the global read lock and wake + everyone, who might want to set a global read lock. + */ + start_waiting_global_read_lock(thd); + /* put tables back for PS rexecuting */ unsent_create_error: lex->link_first_table_back(create_table, link_to_local); @@ -6940,6 +6970,8 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables, { /* Check permissions for used tables in CREATE TABLE ... SELECT */ +#ifdef NOT_NECESSARY_TO_CHECK_CREATE_TABLE_EXIST_WHEN_PREPARING_STATEMENT + /* This code throws an ill error for CREATE TABLE t1 SELECT * FROM t1 */ /* Only do the check for PS, becasue we on execute we have to check that against the opened tables to ensure we don't use a table that is part @@ -6958,6 +6990,7 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables, goto err; } } +#endif if (tables && check_table_access(thd, SELECT_ACL, tables,0)) goto err; } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 5cdb86a6f4c..7e1e295cb44 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1757,7 +1757,7 @@ TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info, } table->reginfo.lock_type=TL_WRITE; - if (!((*lock)= mysql_lock_tables(thd, &table,1))) + if (! ((*lock)= mysql_lock_tables(thd, &table, 1, MYSQL_LOCK_IGNORE_FLUSH))) { VOID(pthread_mutex_lock(&LOCK_open)); hash_delete(&open_cache,(byte*) table); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index b933876f4f3..b67c9f7d600 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -7078,7 +7078,32 @@ simple_ident_q: field_ident: ident { $$=$1;} - | ident '.' ident { $$=$3;} /* Skip schema name in create*/ + | ident '.' ident '.' ident + { + TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first; + if (my_strcasecmp(table_alias_charset, $1.str, table->db)) + { + my_error(ER_WRONG_DB_NAME, MYF(0), $1.str); + YYABORT; + } + if (my_strcasecmp(table_alias_charset, $3.str, + table->table_name)) + { + my_error(ER_WRONG_TABLE_NAME, MYF(0), $3.str); + YYABORT; + } + $$=$5; + } + | ident '.' ident + { + TABLE_LIST *table= (TABLE_LIST*) Select->table_list.first; + if (my_strcasecmp(table_alias_charset, $1.str, table->alias)) + { + my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str); + YYABORT; + } + $$=$3; + } | '.' ident { $$=$2;} /* For Delphi */; table_ident: