From 81ca220b027c93d55f9c7c573e1145c0a03e6f92 Mon Sep 17 00:00:00 2001 From: Radoslaw Bartosiak Date: Wed, 21 Jan 2015 16:12:57 +0100 Subject: [PATCH] Fix catching exceptions in socket helper functions 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 --- src/helpers/creds-socket/creds-socket-inner.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/helpers/creds-socket/creds-socket-inner.cpp b/src/helpers/creds-socket/creds-socket-inner.cpp index bb4ebcc..8b5143e 100644 --- a/src/helpers/creds-socket/creds-socket-inner.cpp +++ b/src/helpers/creds-socket/creds-socket-inner.cpp @@ -22,14 +22,14 @@ * @brief Implementation of internal libcynara-creds-socket functions */ - -#include +#include +#include #include -#include - #include #include +#include + #include #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) -- 2.7.4