Fix catching exceptions in socket helper functions 90/34190/3
authorRadoslaw Bartosiak <r.bartosiak@samsung.com>
Wed, 21 Jan 2015 15:12:57 +0000 (16:12 +0100)
committerRadoslaw Bartosiak <r.bartosiak@samsung.com>
Thu, 22 Jan 2015 14:17:25 +0000 (15:17 +0100)
Cynara socket helpers functions could throw exceptions (GET_CRED
macro in cders-socket-inner.cpp used std::to_string()).
Fixed it with Cynara::tryCatch().

Change-Id: Ic0db847bc04e9817d1afa86310452147f9678431
Signed-off-by: Radoslaw Bartosiak <r.bartosiak@samsung.com>
src/helpers/creds-socket/creds-socket-inner.cpp

index bb4ebcc..8b5143e 100644 (file)
  * @brief       Implementation of internal libcynara-creds-socket functions
  */
 
-
-#include <errno.h>
+#include <cerrno>
+#include <cstring>
 #include <string>
-#include <string.h>
-
 #include <sys/socket.h>
 #include <sys/types.h>
 
+#include <exceptions/TryCatch.h>
+
 #include <cynara-error.h>
 
 #include "creds-socket-inner.h"
@@ -59,16 +59,18 @@ int getClientSmackLabel(int socketFd, char **client) {
 }
 
 #define GET_CRED(SOCK, RESULT, CRED) \
-    struct ucred credentials; \
-    int ret = getCredentials(SOCK, &credentials); \
-    if (ret < 0) \
-        return ret; \
+    return Cynara::tryCatch([&]() { \
+        struct ucred credentials; \
+        int ret = getCredentials(SOCK, &credentials); \
+        if (ret < 0) \
+            return ret; \
  \
-    *RESULT = strdup(std::to_string(credentials.CRED).c_str()); \
-    if (*RESULT == nullptr) \
+        *RESULT = strdup(std::to_string(credentials.CRED).c_str()); \
+        if (*RESULT == nullptr) \
             return CYNARA_API_OUT_OF_MEMORY; \
  \
-    return CYNARA_API_SUCCESS; \
+        return CYNARA_API_SUCCESS; \
+     });
 
 int getClientPid(int socketFd, char **client) {
     GET_CRED(socketFd, client, pid)