Prevent key-manager client crash 57/151357/2
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Wed, 20 Sep 2017 09:19:33 +0000 (11:19 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 21 Sep 2017 14:20:10 +0000 (16:20 +0200)
Key-manager client crashed during pthread_cancel because
try catch sections did not support stack unwind correctly.

Change-Id: I7089160603394a11d94b437bb4f80cf19b632da0

src/manager/client/client-common.cpp

index 9ca3df9..312f334 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
+#include <cxxabi.h>
 
 #include <dpl/errno_string.h>
 #include <dpl/log/log.h>
@@ -331,6 +332,9 @@ int try_catch(const std::function<int()> &func)
                LogError("CKM::MessageBuffer::Exception " << e.DumpToString());
        } catch (const std::exception &e) {
                LogError("STD exception " << e.what());
+       } catch (const abi::__forced_unwind &) {
+               LogDebug("abi::__forced_unwind caught. Thread cancelation.");
+               throw;
        } catch (...) {
                LogError("Unknown exception occured");
        }
@@ -350,6 +354,9 @@ int try_catch_enclosure(const std::function<int()> &func)
        } catch (const std::exception &e) {
                LogError("std exception occured: " << e.what());
                return CKMC_ERROR_UNKNOWN;
+       } catch (const abi::__forced_unwind &) {
+               LogDebug("abi::__forced_unwind caught. Thread cancelation.");
+               throw;
        } catch (...) {
                LogError("Unknown exception occured.");
                return CKMC_ERROR_UNKNOWN;
@@ -370,6 +377,9 @@ void try_catch_async(const std::function<void()> &func,
        } catch (const std::exception &e) {
                LogError("STD exception " << e.what());
                error(CKM_API_ERROR_UNKNOWN);
+       } catch (const abi::__forced_unwind &) {
+               LogDebug("abi::__forced_unwind caught. Thread cancelation.");
+               throw;
        } catch (...) {
                LogError("Unknown exception occured");
                error(CKM_API_ERROR_UNKNOWN);