From 13c7c64da3c474504f2e92850111bceefd169029 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Fri, 6 Jan 2017 12:00:30 -0500 Subject: Add try/catch blocks in noexcept destructors that might throw Flagged by Coverity --- src/lib/prov/pkcs11/p11_module.cpp | 9 ++++++++- src/lib/prov/pkcs11/p11_object.cpp | 11 +++++++++-- src/lib/prov/pkcs11/p11_session.cpp | 17 ++++++++++++----- 3 files changed, 29 insertions(+), 8 deletions(-) (limited to 'src/lib/prov/pkcs11') diff --git a/src/lib/prov/pkcs11/p11_module.cpp b/src/lib/prov/pkcs11/p11_module.cpp index 4ea3dc56d..ba8b659b9 100644 --- a/src/lib/prov/pkcs11/p11_module.cpp +++ b/src/lib/prov/pkcs11/p11_module.cpp @@ -20,7 +20,14 @@ Module::Module(const std::string& file_path, C_InitializeArgs init_args) Module::~Module() BOTAN_NOEXCEPT { - m_low_level->C_Finalize(nullptr, nullptr); + try + { + m_low_level->C_Finalize(nullptr, nullptr); + } + catch(...) + { + // we are noexcept and must swallow any exception here + } } void Module::reload(C_InitializeArgs init_args) diff --git a/src/lib/prov/pkcs11/p11_object.cpp b/src/lib/prov/pkcs11/p11_object.cpp index 872fdf8b7..5f078fd31 100644 --- a/src/lib/prov/pkcs11/p11_object.cpp +++ b/src/lib/prov/pkcs11/p11_object.cpp @@ -92,9 +92,16 @@ ObjectFinder::ObjectFinder(Session& session, const std::vector& searc ObjectFinder::~ObjectFinder() BOTAN_NOEXCEPT { - if(m_search_terminated == false) + try { - module()->C_FindObjectsFinal(m_session.get().handle(), nullptr); + if(m_search_terminated == false) + { + module()->C_FindObjectsFinal(m_session.get().handle(), nullptr); + } + } + catch(...) + { + // ignore error during noexcept function } } diff --git a/src/lib/prov/pkcs11/p11_session.cpp b/src/lib/prov/pkcs11/p11_session.cpp index ceb316169..71397eea5 100644 --- a/src/lib/prov/pkcs11/p11_session.cpp +++ b/src/lib/prov/pkcs11/p11_session.cpp @@ -38,14 +38,21 @@ Session::Session(Slot& slot, SessionHandle handle) Session::~Session() BOTAN_NOEXCEPT { - if(m_handle) + try { - if(m_logged_in) + if(m_handle) { - module()->C_Logout(m_handle, nullptr); + if(m_logged_in) + { + module()->C_Logout(m_handle, nullptr); + } + module()->C_CloseSession(m_handle, nullptr); + m_handle = 0; } - module()->C_CloseSession(m_handle, nullptr); - m_handle = 0; + } + catch(...) + { + // exception during noexcept destructor is ignored } } -- cgit v1.2.3