Fix problems reported on Coverity
authorPawel Polawski <p.polawski@samsung.com>
Wed, 7 Nov 2012 16:46:02 +0000 (17:46 +0100)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 13 Dec 2012 16:30:02 +0000 (17:30 +0100)
[Issue#]        http://cam.sprc.samsung.pl/browse/LINUXSWAP-325
[Bug]           Fix prevent defects.
[Cause]         Bugs in sorce reported by Coverity may cause software
                errors or malfunctions.
[Solution]      Bugs has been fixed.
[Verification]  Rebuild project.

Change-Id: Ibc0d085408f5ef189c09df48e23696b2ec5f1388

src/privilege-control.c

index e406c4e..18503cd 100644 (file)
@@ -110,19 +110,19 @@ static int set_dac(const char* pkg_name)
        {
                if(!strncmp(pkg_name, "developer", 9))
                {
-                       strncpy(usr.user_name, DEV_USER_NAME, strlen(DEV_USER_NAME));
+                       strncpy(usr.user_name, DEV_USER_NAME, sizeof(usr.user_name));
                        usr.uid = DEVELOPER_UID;
                        usr.gid = DEVELOPER_GID;
-                       strncpy(usr.home_dir, DEV_HOME_DIR, strlen(DEV_HOME_DIR));
-                       strncpy(usr.group_list, DEV_GROUP_PATH, strlen(DEV_GROUP_PATH));
+                       strncpy(usr.home_dir, DEV_HOME_DIR, sizeof(usr.home_dir));
+                       strncpy(usr.group_list, DEV_GROUP_PATH, sizeof(usr.group_list));
                }
                else
                {
-                       strncpy(usr.user_name, APP_USER_NAME, strlen(APP_USER_NAME));
+                       strncpy(usr.user_name, APP_USER_NAME, sizeof(usr.user_name));
                        usr.uid = APP_UID;
                        usr.gid = APP_GID;
-                       strncpy(usr.home_dir, APP_HOME_DIR, strlen(APP_HOME_DIR));
-                       strncpy(usr.group_list, APP_GROUP_PATH, strlen(APP_GROUP_PATH));
+                       strncpy(usr.home_dir, APP_HOME_DIR, sizeof(usr.home_dir));
+                       strncpy(usr.group_list, APP_GROUP_PATH, sizeof(usr.group_list));
                }
 
                /*
@@ -137,13 +137,6 @@ static int set_dac(const char* pkg_name)
 
                while(fgets(buf, 10, fp_group) != NULL)
                {
-                       if(buf == NULL)
-                       {
-                               fprintf(stderr, "[ERR] Fail to get gid\n");
-                               result = PC_ERR_INVALID_OPERATION;
-                               goto error;
-                       }
-
                        errno = 0;
                        temp_gid = strtoul(buf, 0, 10);
                        if(errno != 0)  // error occured during strtoul()
@@ -219,6 +212,8 @@ static int set_dac(const char* pkg_name)
        result = PC_OPERATION_SUCCESS;
 
 error:
+    if(fp_group != NULL)
+        fclose(fp_group);
        if(glist != NULL)
                free(glist);