Catch exceptions before returning to cynara 96/252596/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 25 Jan 2021 08:07:44 +0000 (09:07 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 29 Jan 2021 13:13:29 +0000 (14:13 +0100)
Callbacks registered in cynara may throw. Let's not propagate exceptions
to cynara.

Change-Id: Idc3bec6208495d0bfdb4d41c3ea0451352c9715b

src/manager/main/cynara.cpp

index c25031f..0a314e6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -139,7 +139,14 @@ void Cynara::ChangeStatusCallback(
        cynara_async_status status,
        void *ptr)
 {
-       static_cast<Cynara *>(ptr)->ChangeStatus(oldFd, newFd, status);
+       try {
+               static_cast<Cynara *>(ptr)->ChangeStatus(oldFd, newFd, status);
+       } catch (const std::exception& e) {
+               LogError("Cynara::ChangeStatus failed: " << e.what());
+       } catch (...) {
+               LogError("Cynara::ChangeStatus failed with unknown exception");
+       }
+
 }
 
 void Cynara::ProcessResponseCallback(
@@ -148,7 +155,13 @@ void Cynara::ProcessResponseCallback(
        int response,
        void *ptr)
 {
-       static_cast<Cynara *>(ptr)->ProcessResponse(checkId, cause, response);
+       try {
+               static_cast<Cynara *>(ptr)->ProcessResponse(checkId, cause, response);
+       } catch (const std::exception& e) {
+               LogError("Cynara::ProcessResponse failed: " << e.what());
+       } catch (...) {
+               LogError("Cynara::ProcessResponse failed with unknown exception");
+       }
 }
 
 bool Cynara::GetUserFromSocket(int socket, std::string &user)