modify svace defect 12/65012/2 accepted/tizen/common/20160407.132344 accepted/tizen/common/20160411.125546 accepted/tizen/mobile/20160411.005727 submit/tizen/20160407.020722 submit/tizen/20160411.002646 submit/tizen_mobile/20160408.003401
authorSEUNGTAEK HAN <s.t.han@samsung.com>
Thu, 7 Apr 2016 00:58:02 +0000 (09:58 +0900)
committerSEUNGTAEK HAN <s.t.han@samsung.com>
Thu, 7 Apr 2016 01:54:48 +0000 (10:54 +0900)
Change-Id: If478072643103f9dc17b737debb01c585b431230

client/src/PrivacyChecker.cpp
client/src/SocketClient.cpp
common/src/SocketStream.cpp
server/src/CynaraService.cpp
server/src/PrivacyGuardDb.cpp
server/src/SocketService.cpp

index f720615..62f2ac8 100755 (executable)
@@ -26,6 +26,8 @@
 #include "SocketClient.h"
 #include "Utils.h"
 
+#define BUF_SIZE 256
+
 bool PrivacyChecker::m_isInitialized = false;
 bool PrivacyChecker::m_isMonitorEnable = false;
 std::map < std::string, bool >PrivacyChecker::m_privacyCache;
@@ -73,8 +75,9 @@ PrivacyChecker::initializeGMain(void)
        TryReturn(m_pLoop != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, ,"cannot create m_pLoop");
 
        std::unique_lock<std::mutex> lock(m_dbusMutex);
+       char buf[BUF_SIZE];
        int res = pthread_create(&m_signalThread, NULL, &runSignalListenerThread, NULL);
-       TryReturn(res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, errno = res;, "Failed to create listener thread :%s", strerror(res));
+       TryReturn(res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, errno = res;, "Failed to create listener thread :%s", strerror_r(res, buf, sizeof(buf)));
 
        m_isInitialized = true;
 
index cb99678..84a3b53 100755 (executable)
@@ -25,6 +25,8 @@
 #include "SocketClient.h"
 #include "Utils.h"
 
+#define BUF_SIZE 256
+
 #define throwWithErrnoMessage(specificInfo)    do {\
                                                                                                PG_LOGE("%s : %s", specificInfo, strerror(errno)); \
                                                                                                return -1; \
@@ -40,8 +42,9 @@ SocketClient::SocketClient(const std::string& interfaceName)
 int SocketClient::connect()
 {
        struct sockaddr_un remote;
+       char buf[BUF_SIZE];
        m_socketFd = socket(AF_UNIX, SOCK_STREAM,0);
-       TryReturn( m_socketFd != -1, PRIV_GUARD_ERROR_IPC_ERROR, , "socket : %s", strerror(errno));
+       TryReturn( m_socketFd != -1, PRIV_GUARD_ERROR_IPC_ERROR, , "socket : %s", strerror_r(errno, buf, sizeof(buf)));
 
        int res;
        //socket needs to be nonblocking, because read can block after select
@@ -49,13 +52,13 @@ int SocketClient::connect()
        if ( (flags = fcntl(m_socketFd, F_GETFL, 0)) == -1 )
                flags = 0;
        res = fcntl(m_socketFd, F_SETFL, flags | O_NONBLOCK);
-       TryReturn( m_socketFd != -1, PRIV_GUARD_ERROR_IPC_ERROR, , "fcntl : %s", strerror(errno));
+       TryReturn( m_socketFd != -1, PRIV_GUARD_ERROR_IPC_ERROR, , "fcntl : %s", strerror_r(errno, buf, sizeof(buf)));
 
        bzero(&remote, sizeof(remote));
        remote.sun_family = AF_UNIX;
-       strcpy(remote.sun_path, m_serverAddress.c_str());
+       strncpy(remote.sun_path, m_serverAddress.c_str(), strlen(m_serverAddress.c_str()));
        res = ::connect(m_socketFd, (struct sockaddr *)&remote, SUN_LEN(&remote));
-       TryReturn( res != -1, PRIV_GUARD_ERROR_IPC_ERROR, , "connect : %s", strerror(errno));
+       TryReturn( res != -1, PRIV_GUARD_ERROR_IPC_ERROR, , "connect : %s", strerror_r(errno, buf, sizeof(buf)));
 
        m_socketConnector.reset(new SocketConnection(m_socketFd));
 
index bc90bc0..5672ebe 100755 (executable)
 #define WRITE_TIMEOUT_SEC 0
 #define WRITE_TIMEOUT_NSEC 100000000
 #define MAX_BUFFER 10240
+#define BUF_SIZE 256
 
 int
 SocketStream::throwWithErrnoMessage(std::string function_name)
 {
-       PG_LOGE("%s : %s", function_name.c_str(), strerror(errno));
+       char buf[BUF_SIZE];
+       PG_LOGE("%s : %s", function_name.c_str(), strerror_r(errno, buf, sizeof(buf)));
        return errno;
 }
 
@@ -47,6 +49,7 @@ SocketStream::readStream(size_t num, void* pBytes)
 
        char partBuffer[MAX_BUFFER];
        std::string wholeBuffer;
+       char buf[BUF_SIZE];
 
        fd_set rset, allset;
        int maxFd;
@@ -73,7 +76,7 @@ SocketStream::readStream(size_t num, void* pBytes)
                {
                        if (errno == EINTR)
                                continue;
-                       PG_LOGD("pselect : %s", strerror(errno));
+                       PG_LOGD("pselect : %s", strerror_r(errno, buf, sizeof(buf)));
                        return -1;
                }
                //This means pselect got timedout
@@ -88,7 +91,7 @@ SocketStream::readStream(size_t num, void* pBytes)
                        {
                                if(errno == ECONNRESET || errno == ENOTCONN || errno == ETIMEDOUT)
                                {
-                                       PG_LOGI("Connection closed : %s", strerror(errno));
+                                       PG_LOGI("Connection closed : %s", strerror_r(errno, buf, sizeof(buf)));
                                        return -1;
                                }
                                else if (errno != EAGAIN && errno != EWOULDBLOCK){
@@ -120,6 +123,7 @@ SocketStream::writeStream(size_t num, const void* pBytes)
 
        fd_set wset, allset;
        int maxFd;
+       char buf[BUF_SIZE];
 
        timespec timeout;
 
@@ -144,7 +148,7 @@ SocketStream::writeStream(size_t num, const void* pBytes)
                {
                        if(errno == EINTR)
                                continue;
-                       PG_LOGD("pselect : %s", strerror(errno));
+                       PG_LOGD("pselect : %s", strerror_r(errno, buf, sizeof(buf)));
                        return -1;
                }
 
@@ -154,7 +158,7 @@ SocketStream::writeStream(size_t num, const void* pBytes)
                        {
                                if(errno == ECONNRESET || errno == EPIPE)
                                {
-                                       PG_LOGI("Connection closed : %s", strerror(errno));
+                                       PG_LOGI("Connection closed : %s", strerror_r(errno, buf, sizeof(buf)));
                                        return -1;
 
                                }
index 569fe90..e1c4d6d 100755 (executable)
@@ -28,6 +28,8 @@
 #include "CynaraService.h"
 #include "PrivacyGuardDb.h"
 
+#define BUF_SIZE 256
+
 static cynara_monitor_configuration *p_conf;
 static cynara_monitor *p_cynara_monitor;
 static cynara_monitor_entry **monitor_entries;
@@ -75,15 +77,16 @@ CynaraService::start(void)
        PG_LOGI("CynaraService starting");
 
        int res = 0;
+       char buf[256];
 
        sigset_t sigset;
        sigemptyset(&sigset);
        res = pthread_sigmask(SIG_BLOCK, &sigset, NULL);
-       TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "pthread_sigmask : %s", strerror(errno));
+       TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "pthread_sigmask : %s", strerror_r(errno, buf, sizeof(buf)));
 
        pthread_t cynaraThread;
        res = pthread_create(&cynaraThread, NULL, &getEntriesThread, this);
-       TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror(res));
+       TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror_r(errno, buf, sizeof(buf)));
 
        m_cynaraThread = cynaraThread;
 
@@ -187,11 +190,12 @@ CynaraService::stop(void)
 {
        PG_LOGI("Stopping");
 
+       char buf[BUF_SIZE];
        int returned_value;
        if((returned_value = pthread_kill(m_cynaraThread, m_signalToClose)) < 0)
        {
                errno = returned_value;
-               PG_LOGE("pthread_kill() : %s", strerror(errno));
+               PG_LOGE("pthread_kill() : %s", strerror_r(errno, buf, sizeof(buf)));
                return PRIV_GUARD_ERROR_IPC_ERROR;
        }
        pthread_join(m_cynaraThread, NULL);
index 8342a6a..af54ebe 100755 (executable)
@@ -71,8 +71,9 @@ int
 PrivacyGuardDb::PgAddPrivacyAccessLog(const int userId, std::list < std::pair < std::string, std::string > > logInfoList)
 {
        time_t current_date;
+       struct tm tm;
        current_date = time(NULL);
-       localtime(&current_date);
+       localtime_r(&current_date, &tm);
 
        if(current_date <= 0) {
                return PRIV_GUARD_ERROR_INVALID_PARAMETER;
@@ -184,8 +185,9 @@ int
 PrivacyGuardDb::PgAddPrivacyAccessLogTest(const int userId, const std::string packageId, const std::string privacyId)
 {
        time_t current_date;
+       struct tm tm;
        current_date = time(NULL);
-       localtime(&current_date);
+       localtime_r(&current_date, &tm);
 
        if(current_date <= 0) {
                return PRIV_GUARD_ERROR_INVALID_PARAMETER;
index 1f1ac30..2ce1d08 100755 (executable)
@@ -30,6 +30,8 @@
 #include "SocketService.h"
 #include "SocketConnection.h"
 
+#define BUF_SIZE 256
+
 const int SocketService::MAX_LISTEN = 5;
 
 SocketService::SocketService(void)
@@ -50,20 +52,21 @@ SocketService::initialize(void)
 {
        PG_LOGI("SocketService initializing");
 
+       char buf[BUF_SIZE];
        m_listenFd = socket(AF_UNIX, SOCK_STREAM, 0);
-       TryReturn( m_listenFd != -1, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "socket : %s", strerror(errno));
+       TryReturn( m_listenFd != -1, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "socket : %s", strerror_r(errno, buf, sizeof(buf)));
 
        int flags = -1;
        int res;
        if ( (flags = fcntl(m_listenFd, F_GETFL, 0)) == -1)
                flags = 0;
        res = fcntl(m_listenFd, F_SETFL, flags | O_NONBLOCK);
-       TryReturn( res != -1, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "fcntl : %s", strerror(errno));
+       TryReturn( res != -1, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "fcntl : %s", strerror_r(errno, buf, sizeof(buf)));
 
        sockaddr_un server_address;
        bzero(&server_address, sizeof(server_address));
        server_address.sun_family = AF_UNIX;
-       strcpy(server_address.sun_path, SERVER_ADDRESS.c_str());
+       strncpy(server_address.sun_path, SERVER_ADDRESS.c_str(), strlen(SERVER_ADDRESS.c_str()));
        unlink(server_address.sun_path);
 
        mode_t socket_umask, original_umask;
@@ -71,7 +74,7 @@ SocketService::initialize(void)
        original_umask = umask(socket_umask);
 
        res = bind(m_listenFd, (struct sockaddr*)&server_address, SUN_LEN(&server_address));
-       TryReturn( res != -1, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "bind : %s", strerror(errno));
+       TryReturn( res != -1, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "bind : %s", strerror_r(errno, buf, sizeof(buf)));
 
        umask(original_umask);
 
@@ -94,12 +97,13 @@ SocketService::start(void)
 //     }
 
        int res = 0;
+       char buf[BUF_SIZE];
        res = pthread_sigmask(SIG_BLOCK, &sigset, NULL);
-       TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "pthread_sigmask : %s", strerror(errno));
+       TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "pthread_sigmask : %s", strerror_r(errno, buf, sizeof(buf)));
 
        pthread_t mainThread;
        res = pthread_create(&mainThread, NULL, &serverThread, this);
-       TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror(res));
+       TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror_r(res, buf, sizeof(buf)));
 
        m_mainThread = mainThread;
 
@@ -125,8 +129,9 @@ SocketService::serverThread(void* pData)
 int
 SocketService::mainloop(void)
 {
+       char buf[BUF_SIZE];
        if( listen(m_listenFd, MAX_LISTEN) == -1 ){
-               PG_LOGE("listen : %s", strerror(errno));
+               PG_LOGE("listen : %s", strerror_r(errno, buf, sizeof(buf)));
                return PRIV_GUARD_ERROR_IPC_ERROR;
        }
 
@@ -135,14 +140,14 @@ SocketService::mainloop(void)
        sigset_t sigset;
        int res;
        res = sigemptyset(&sigset);
-       TryReturn( res != -1, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "sigemptyset : %s", strerror(errno));
+       TryReturn( res != -1, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "sigemptyset : %s", strerror_r(errno, buf, sizeof(buf)));
 
 //     if( sigaddset(&sigset, m_signalToClose) == -1) {
 //             PG_LOGE("sigaddset : %s", strerror(errno));
 //             return -1;
 //     }
        signal_fd = signalfd(-1, &sigset, 0);
-       TryReturn( signal_fd >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "signalfd : %s", strerror(errno));
+       TryReturn( signal_fd >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "signalfd : %s", strerror_r(errno, buf, sizeof(buf)));
 
        //Setting descriptors for pselect
        fd_set allset, rset;
@@ -176,7 +181,7 @@ SocketService::mainloop(void)
                        signalfd_siginfo siginfo;
                        ssize_t res;
                        res = read(signal_fd, &siginfo, sizeof(siginfo));
-                       TryReturn( res > 0, PRIV_GUARD_ERROR_IPC_ERROR, closeConnections();, "read : %s", strerror(errno));
+                       TryReturn( res > 0, PRIV_GUARD_ERROR_IPC_ERROR, closeConnections();, "read : %s", strerror_r(errno, buf, sizeof(buf)));
                        TryReturn( (size_t)res == sizeof(siginfo), PRIV_GUARD_ERROR_IPC_ERROR, closeConnections();, "couldn't read whole siginfo");
 
                        if((int)siginfo.ssi_signo == m_signalToClose)
@@ -194,7 +199,7 @@ SocketService::mainloop(void)
                {
                        int clientFd;
                        clientFd = accept(m_listenFd, NULL, NULL);
-                       TryReturn( clientFd != -1, PRIV_GUARD_ERROR_IPC_ERROR, closeConnections();, "accept : %s", strerror(errno));
+                       TryReturn( clientFd != -1, PRIV_GUARD_ERROR_IPC_ERROR, closeConnections();, "accept : %s", strerror_r(errno, buf, sizeof(buf)));
 
                        PG_LOGI("Got incoming connection");
                        ConnectionInfo * connection = new ConnectionInfo(clientFd, (void *)this);
@@ -284,10 +289,11 @@ int
 SocketService::stop(void)
 {
        PG_LOGI("Stopping");
+       char buf[BUF_SIZE];
        if(close(m_listenFd) == -1)
                if(errno != ENOTCONN)
                {
-                       PG_LOGE("close() : %s", strerror(errno));
+                       PG_LOGE("close() : %s", strerror_r(errno, buf, sizeof(buf)));
                        return PRIV_GUARD_ERROR_IPC_ERROR;
                }
 
@@ -295,7 +301,7 @@ SocketService::stop(void)
        if((returned_value = pthread_kill(m_mainThread, m_signalToClose)) < 0)
        {
                errno = returned_value;
-               PG_LOGE("pthread_kill() : %s", strerror(errno));
+               PG_LOGE("pthread_kill() : %s", strerror_r(errno, buf, sizeof(buf)));
                return PRIV_GUARD_ERROR_IPC_ERROR;
        }
        pthread_join(m_mainThread, NULL);
@@ -360,12 +366,13 @@ void
 SocketService::closeConnections(void)
 {
        int clientSocket;
+       char buf[BUF_SIZE];
        PG_LOGI("Closing client sockets");
        while(popClientSocket(&clientSocket))
        {
                if(close(clientSocket) == -1)
                {
-                       PG_LOGE("close() : %s", strerror(errno));
+                       PG_LOGE("close() : %s", strerror_r(errno, buf, sizeof(buf)));
                }
        }