Prevent related bugfixes.
authorMariusz Domanski <m.domanski@samsung.com>
Tue, 15 Jan 2013 13:58:55 +0000 (14:58 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Tue, 15 Jan 2013 15:26:00 +0000 (16:26 +0100)
[Issue] N/A
[Bug] Bugs found by Coverity.
[Cause] N/A
[Solution] Checking varibale values, catching exception.
[Verification] Build security-server, run all tests.

Change-Id: Ide143746a4a4ccc4cc575f14cfb3529d3b32d088

src/main.cpp
src/security-srv/server/security-server-cookie.c
src/security-srv/server/security-server-main.c

index c605ac7046ad26aa1cd12f96ae60d0b89ed775ce..4b16270c4fc9049543af4ce07af190d43628440a 100644 (file)
@@ -43,8 +43,13 @@ int main(int argc, char* argv[])
     }
 
     DPL::SingleInstance instance;
-    if (!instance.TryLock(DAEMON_INSTANCE_UUID)) {
-        LogError("Security Daemon is already running");
+    try {
+        if (!instance.TryLock(DAEMON_INSTANCE_UUID)) {
+            LogError("Security Daemon is already running");
+            return -1;
+        }
+    } catch (const DPL::SingleInstance::Exception::LockError &e) {
+        LogError(e.DumpToString());
         return -1;
     }
 
index 2cb3839594fd17f4460b5c5ce7660bf39f7ec344..518134b707c0501ba99c0e39aea1a65109eb7226 100644 (file)
@@ -327,7 +327,7 @@ int generate_random_cookie(unsigned char *cookie, int size)
        close(fd);
        ret = SECURITY_SERVER_SUCCESS;
 error:
-       if(fd > 0)
+       if(fd >= 0)
                close(fd);
        return ret;
 }
index c0b183a91b0977233c69cacae4240e22c9a626e7..1cd5cfb84487db7770913e528645b1fa22f10e8b 100644 (file)
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <pthread.h>
+#include <limits.h>
 
 #include "security-server-cookie.h"
 #include "security-server-common.h"
@@ -786,7 +787,7 @@ int process_tool_request(int client_sockfd, int server_sockfd)
        /* Receive Total number of argv */
        argcnum = 0;
        retval = read(client_sockfd, &argcnum, sizeof(int));
-       if(retval < sizeof(int))
+       if((retval < sizeof(int)) || argcnum > (UINT_MAX/sizeof(char *))-2 || argcnum < 0)
        {
                SEC_SVR_DBG("Error: argc recieve failed: %d", retval);
                retval = send_generic_response(client_sockfd,