From 21a3aabf0e4e9d643607fc7117810ae6cce2696d Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Fri, 26 Apr 2013 15:57:58 +0200 Subject: [PATCH] Klocwork bugfixes [Issue#] SSDWSSP-213 [Feature/Bug] N/A [Problem] Issues reported by Klocwork [Cause] N/A [Solution] Issues fixed [Verification] Build and run libprivilege tests Change-Id: I3328b94d351edf263f316a1c7ae3019604195d22 --- src/access-db.c | 10 +++++++++- src/privilege-control.c | 14 +++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/access-db.c b/src/access-db.c index c558f4e..61609ec 100644 --- a/src/access-db.c +++ b/src/access-db.c @@ -62,8 +62,10 @@ static element_t* add_element (element_t* elem, const char* value) return NULL; new_element->value = malloc(sizeof(char) * (SMACK_LABEL_LEN + 1) ); - if (NULL == new_element->value) + if (NULL == new_element->value) { + free(new_element); return NULL; + } strncpy(new_element->value, value, SMACK_LABEL_LEN); new_element->value[SMACK_LABEL_LEN] = '\0'; @@ -278,6 +280,12 @@ int get_app_gids(const char *app_id, unsigned **gids, int *len) } } + if (!app_id_tmp) { + C_LOGE("No group id found"); + ret = PC_ERR_FILE_OPERATION; + goto out; + } + if (!strcmp(app_id, app_id_tmp)) { unsigned *gids_realloc = realloc(*gids, sizeof(unsigned) * (*len + 1)); if (gids_realloc == NULL) { diff --git a/src/privilege-control.c b/src/privilege-control.c index 02acb61..dcf950b 100644 --- a/src/privilege-control.c +++ b/src/privilege-control.c @@ -836,14 +836,14 @@ static int register_app_for_av(const char * app_id) ret = smack_accesses_new(&smack); if (ret != PC_OPERATION_SUCCESS) { C_LOGE("smack_accesses_new failed"); - goto out; + return ret; } // Reading labels of all installed anti viruses from "database" ret = get_all_avs_ids(&smack_label_av_list, &smack_label_av_list_len); - if (ret != PC_OPERATION_SUCCESS ) { + if (ret != PC_OPERATION_SUCCESS) { C_LOGE("Error while geting data from database"); - goto out; + return ret; } // for each anti-virus put rule: "anti_virus_id app_id rwx" @@ -1439,8 +1439,8 @@ API int add_api_feature(app_type_t app_type, C_LOGD("Enter function: %s", __func__); int ret = PC_OPERATION_SUCCESS; - char* smack_file = NULL; - char* dac_file = NULL; + char* smack_file AUTO_FREE; + char* dac_file AUTO_FREE; struct smack_accesses* accesses = NULL; FILE* file = NULL; @@ -1448,7 +1448,7 @@ API int add_api_feature(app_type_t app_type, // get feature SMACK file name ret = perm_file_path(&smack_file, app_type, api_feature_name, ".smack"); - if (ret != PC_OPERATION_SUCCESS ) { + if (ret != PC_OPERATION_SUCCESS || !smack_file ) { return ret; } @@ -1462,7 +1462,7 @@ API int add_api_feature(app_type_t app_type, if (list_of_db_gids && list_size > 0) { // get feature DAC file name ret = perm_file_path(&dac_file, app_type, api_feature_name, ".dac"); - if (ret != PC_OPERATION_SUCCESS ) { + if (ret != PC_OPERATION_SUCCESS || !dac_file ) { return ret; } -- 2.7.4