Fix to check return value 05/194605/1
authorYunjin Lee <yunjin-.lee@samsung.com>
Thu, 6 Dec 2018 02:01:20 +0000 (11:01 +0900)
committerYunjin Lee <yunjin-.lee@samsung.com>
Thu, 6 Dec 2018 06:44:54 +0000 (06:44 +0000)
- Check return value of sqlite3_exec() for begin and commit
transaction.

Change-Id: I887340a7c7485ea06d898473393655d75641b9bc
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
(cherry picked from commit b77f85bacb993469df47ae1a043024f2cc84c02a)

capi/src/privilege_db_manager.c

index cbdf92f..64e5f23 100755 (executable)
@@ -786,7 +786,7 @@ int privilege_db_manager_set_black_list(privilege_manager_policy_type_e policy_t
        if (ret != PRIVILEGE_DB_MANAGER_ERR_NONE)
                return ret;
 
-       sqlite3_exec(db, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL);
+       TryReturn(sqlite3_exec(db, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL) == SQLITE_OK, __finalize_db(db, NULL, NULL), PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL, "[DB_FAIL] sqlite3_exec for BEGIN IMMEDIATE TRANSACTION failed");
        GList *l = NULL;
        for (l = privilege_list; l != NULL; l = l->next) {
                char *privilege_name = (char *)l->data;
@@ -808,7 +808,7 @@ int privilege_db_manager_set_black_list(privilege_manager_policy_type_e policy_t
                sqlite3_free(sql);
        }
 
-       sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL);
+       TryReturn(sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL) == SQLITE_OK, __finalize_db(db, stmt, NULL), PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL, "[DB_FAIL] sqlite3_exec for COMMIT TRANSACTION failed");
        __finalize_db(db, stmt, NULL);
        return PRIVILEGE_DB_MANAGER_ERR_NONE;
 }
@@ -821,7 +821,7 @@ int privilege_db_manager_unset_black_list(privilege_manager_policy_type_e policy
        if (ret != PRIVILEGE_DB_MANAGER_ERR_NONE)
                return ret;
 
-       sqlite3_exec(db, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL);
+       TryReturn(sqlite3_exec(db, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL) == SQLITE_OK, __finalize_db(db, NULL, NULL), PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL, "[DB_FAIL] sqlite3_exec for BEGIN IMMEDIATE TRANSACTION failed");
        GList *l = NULL;
        for (l = privilege_list; l != NULL; l = l->next) {
                char *privilege_name = (char *)l->data;
@@ -843,7 +843,7 @@ int privilege_db_manager_unset_black_list(privilege_manager_policy_type_e policy
                sqlite3_free(sql);
        }
 
-       sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL);
+       TryReturn(sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL) == SQLITE_OK, __finalize_db(db, stmt, NULL), PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL, "[DB_FAIL] sqlite3_exec for COMMIT TRANSACTION failed");
        __finalize_db(db, stmt, NULL);
        return PRIVILEGE_DB_MANAGER_ERR_NONE;
 }
@@ -860,7 +860,7 @@ int privilege_db_manager_set_package_critical_privilege_info(const uid_t uid, co
        ret = privilege_db_manager_get_mapped_privilege_list(api_version, package_type, critical_privilege_list, &mapped_privilege_list);
        TryReturn(ret == PRIVILEGE_DB_MANAGER_ERR_NONE && mapped_privilege_list != NULL, __finalize_db(db, stmt, NULL), PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL, "[DB_FAIL] privilege_db_manager_get_mapped_privilege_list failed");
 
-       sqlite3_exec(db, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL);
+       TryReturn(sqlite3_exec(db, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL) == SQLITE_OK, __finalize_db(db, NULL, NULL), PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL, "[DB_FAIL] sqlite3_exec for BEGIN IMMEDIATE TRANSACTION failed");
        GList *l = NULL;
        for (l = mapped_privilege_list; l != NULL; l = l->next) {
                char *privilege_name = (char *)l->data;
@@ -890,7 +890,7 @@ int privilege_db_manager_set_package_critical_privilege_info(const uid_t uid, co
        }
        g_list_free_full(mapped_privilege_list, free);
 
-       sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL);
+       TryReturn(sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL) == SQLITE_OK, __finalize_db(db, stmt, NULL), PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL, "[DB_FAIL] sqlite3_exec for COMMIT TRANSACTION failed");
        __finalize_db(db, stmt, NULL);
        return PRIVILEGE_DB_MANAGER_ERR_NONE;
 }
@@ -906,7 +906,7 @@ int privilege_db_manager_set_package_privacy_privilege_info(const uid_t uid, con
        ret = privilege_db_manager_get_mapped_privilege_list(api_version, package_type, privilege_list, &mapped_privilege_list);
        TryReturn(ret == PRIVILEGE_DB_MANAGER_ERR_NONE && mapped_privilege_list != NULL, __finalize_db(db, stmt, NULL), PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL, "[DB_FAIL] privilege_db_manager_get_mapped_privilege_list failed");
 
-       sqlite3_exec(db, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL);
+       TryReturn(sqlite3_exec(db, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL) == SQLITE_OK, __finalize_db(db, NULL, NULL), PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL, "[DB_FAIL] sqlite3_exec for BEGIN IMMEDIATE TRANSACTION failed");
        GList *l = NULL;
        for (l = mapped_privilege_list; l != NULL; l = l->next) {
                char *privilege_name = (char *)l->data;
@@ -936,7 +936,7 @@ int privilege_db_manager_set_package_privacy_privilege_info(const uid_t uid, con
        }
        g_list_free_full(mapped_privilege_list, free);
 
-       sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL);
+       TryReturn(sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL) == SQLITE_OK, __finalize_db(db, stmt, NULL), PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL, "[DB_FAIL] sqlite3_exec for COMMIT TRANSACTION failed");
        __finalize_db(db, stmt, NULL);
        return PRIVILEGE_DB_MANAGER_ERR_NONE;
 }