Fixing segfault in libprivilege-control
authorZbigniew Jasinski <z.jasinski@samsung.com>
Tue, 9 Jul 2013 10:01:28 +0000 (12:01 +0200)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Tue, 9 Jul 2013 12:44:20 +0000 (12:44 +0000)
[Issue#]        SSDWSSP-371
[Bug/Feature]   segfault in libprivilege-control
[Cause]         In set_app_privilege() one should be able to get smack context
                from path even if there's no SMACK on the device.
[Solution]      Added function params checking.
[Verification]  Running libprivilege-control-test.

Change-Id: Id9db1f59aa2c95eab8781747ef6a00bbc6400cc2

src/privilege-control.c

index 25483f2..06c2bce 100644 (file)
@@ -403,6 +403,7 @@ static int set_dac(const char *smack_label, const char *pkg_name)
                fclose(fp_group);
                fp_group = NULL;
 
+               if(NULL != smack_label)
                {
                        gid_t *glist_new;
                        int i, cnt;
@@ -632,6 +633,11 @@ API int set_app_privilege(const char* name, const char* type, const char* path)
        int were_rules_loaded = 0;
        char *smack_label AUTO_FREE;
 
+       if (NULL == name) {
+               C_LOGE("Error invalid param");
+               return PC_ERR_INVALID_PARAM;
+       }
+
        if (path != NULL && have_smack()) {
                ret = get_smack_from_binary(&smack_label, path, verify_app_type(type, path));
                if (ret != PC_OPERATION_SUCCESS)
@@ -657,6 +663,12 @@ API int set_app_privilege(const char* name, const char* type, const char* path)
                        return ret;
        }
 
+       if (path != NULL && !have_smack()) {
+               ret = get_smack_from_binary(&smack_label, path, verify_app_type(type, path));
+               if (ret != PC_OPERATION_SUCCESS)
+                       return ret;
+       }
+
        return set_dac(smack_label, name);
 }