Fix ASAN build issue 69/233669/1
authorJusung Son <jusung07.son@samsung.com>
Mon, 18 May 2020 06:48:23 +0000 (15:48 +0900)
committerJusung Son <jusung07.son@samsung.com>
Mon, 18 May 2020 06:48:23 +0000 (15:48 +0900)
Change-Id: I4a202a7f60733b9087d928f667588840d22546eb
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
src/data_control_internal.c

index ca4e1ccea4d8f5e25c0f204b9caba6feafefba0f..364f80e736bff0d0310f0bce66cd0ff3307d4b4e 100644 (file)
@@ -132,7 +132,7 @@ static char *__get_victim(GHashTable *hash)
        return victim_key;
 }
 
-static void __insert_hash(GHashTable *hash, const char *key,
+static struct datacontrol_cert_info* __insert_hash(GHashTable *hash, const char *key,
                bool is_map, cert_status_type status)
 {
        struct datacontrol_cert_info *cert_info;
@@ -149,7 +149,7 @@ static void __insert_hash(GHashTable *hash, const char *key,
                        sizeof(struct datacontrol_cert_info));
        if (cert_info == NULL) {
                _LOGE("out of memory.");
-               return;
+               return NULL;
        }
 
        if (is_map)
@@ -163,10 +163,11 @@ static void __insert_hash(GHashTable *hash, const char *key,
        if (hash_key == NULL) {
                free(cert_info);
                _LOGE("out of memory.");
-               return;
+               return NULL;
        }
 
        g_hash_table_insert(hash, hash_key, cert_info);
+       return cert_info;
 }
 
 static void __free_cb_info(gpointer data)
@@ -2187,7 +2188,6 @@ int _check_cert(const char *provider_id, bool is_map,
 {
        int ret;
        bool is_trusted;
-       bool is_update = false;
        char *provider_appid;
        char appid[255];
        GHashTable *hash_table;
@@ -2216,8 +2216,12 @@ int _check_cert(const char *provider_id, bool is_map,
                        return DATA_CONTROL_ERROR_NONE;
                else if (*status == CERT_MISMATCH)
                        return DATA_CONTROL_ERROR_PERMISSION_DENIED;
-
-               is_update = true;
+       } else {
+               cert_info = __insert_hash(hash_table, provider_id, is_map, CERT_UNCHECKED);
+               if (cert_info == NULL) {
+                       return DATA_CONTROL_ERROR_OUT_OF_MEMORY;
+               }
+               status = is_map ? &cert_info->map : &cert_info->sql;
        }
 
        ret = pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(provider_id,
@@ -2228,10 +2232,7 @@ int _check_cert(const char *provider_id, bool is_map,
        }
 
        if (!is_trusted) {
-               if (is_update)
-                       *status = CERT_MATCH;
-               else
-                       __insert_hash(hash_table, provider_id, is_map, CERT_MATCH);
+               *status = CERT_MATCH;
                free(provider_appid);
                return DATA_CONTROL_ERROR_NONE;
        }
@@ -2256,19 +2257,12 @@ int _check_cert(const char *provider_id, bool is_map,
        if (res != PMINFO_CERT_COMPARE_MATCH) {
                _LOGE("certificate mismatch. provider : %s consumer %s",
                                provider_appid, consumer_appid);
-               if (is_update)
-                       *status = CERT_MISMATCH;
-               else
-                       __insert_hash(hash_table, provider_id, is_map, CERT_MISMATCH);
+               *status = CERT_MISMATCH;
                free(provider_appid);
                return DATA_CONTROL_ERROR_PERMISSION_DENIED;
        }
 
-       if (is_update)
-               *status = CERT_MATCH;
-       else
-               __insert_hash(hash_table, provider_id, is_map, CERT_MATCH);
-
+       *status = CERT_MATCH;
        free(provider_appid);
 
        return DATA_CONTROL_ERROR_NONE;