libsemanage: move modinfo_tmp definition before goto cleanup

In semanage_direct_set_module_info() and semanage_direct_list_all()
functions, when modinfo_tmp variable gets initialized, a branch to
"cleanup" label may have already been taken.  This leads to this
variable being possibly used uninitialized in these functions.

This is reported by clang:

    direct_api.c:2491:41: error: variable 'modinfo_tmp' may be
    uninitialized when used here [-Werror,-Wconditional-uninitialized]
            ret = semanage_module_info_destroy(sh, modinfo_tmp);
                                                   ^~~~~~~~~~~
    direct_api.c:2334:2: note: variable 'modinfo_tmp' is declared here
            semanage_module_info_t *modinfo_tmp = NULL;
            ^

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
This commit is contained in:
Nicolas Iooss 2016-01-31 11:36:38 +01:00 committed by Steve Lawrence
parent a11ce9dae5
commit 033ea27c09
1 changed files with 3 additions and 4 deletions

View File

@ -2136,6 +2136,7 @@ static int semanage_direct_set_module_info(semanage_handle_t *sh,
char fn[PATH_MAX];
const char *path = NULL;
int enabled = 0;
semanage_module_info_t *modinfo_tmp = NULL;
semanage_module_key_t modkey;
ret = semanage_module_key_init(sh, &modkey);
@ -2144,8 +2145,6 @@ static int semanage_direct_set_module_info(semanage_handle_t *sh,
goto cleanup;
}
semanage_module_info_t *modinfo_tmp = NULL;
/* check transaction */
if (!sh->is_in_transaction) {
if (semanage_begin_transaction(sh) < 0) {
@ -2316,6 +2315,8 @@ static int semanage_direct_list_all(semanage_handle_t *sh,
uint16_t priority = 0;
semanage_module_info_t *modinfo_tmp = NULL;
semanage_module_info_t modinfo;
ret = semanage_module_info_init(sh, &modinfo);
if (ret != 0) {
@ -2323,8 +2324,6 @@ static int semanage_direct_list_all(semanage_handle_t *sh,
goto cleanup;
}
semanage_module_info_t *modinfo_tmp = NULL;
if (sh->is_in_transaction) {
toplevel = semanage_path(SEMANAGE_TMP, SEMANAGE_MODULES);
} else {