Skip to content

Commit

Permalink
opal/mca: fix ompi_info segfault due to empty enumerator
Browse files Browse the repository at this point in the history
This patch fixes a segfault that the enumerator variable is not assigned in
mca_base_var_enum_create_flag, leaving it as NULL. This causes invalid memory
access later when it is iterated over.

Signed-off-by: Wenduo Wang <[email protected]>
  • Loading branch information
wenduwan committed Nov 29, 2023
1 parent 8ddc997 commit 8ac1ea9
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions opal/mca/base/mca_base_var_enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ int mca_base_var_enum_create_flag(const char *name, const mca_base_var_enum_valu
{
mca_base_var_enum_flag_t *new_enum;
int i;
int __opal_attribute_unused__ all_flags = 0;

*enumerator = NULL;

Expand All @@ -460,8 +461,6 @@ int mca_base_var_enum_create_flag(const char *name, const mca_base_var_enum_valu
return OPAL_ERR_OUT_OF_RESOURCE;
}

#if OPAL_ENABLE_DEBUG
int all_flags = 0;
for (i = 0; i < new_enum->super.enum_value_count; ++i) {
new_enum->enum_flags[i].flag = flags[i].flag;
new_enum->enum_flags[i].string = strdup(flags[i].string);
Expand All @@ -474,7 +473,6 @@ int mca_base_var_enum_create_flag(const char *name, const mca_base_var_enum_valu
assert(flags[i].flag);
all_flags |= flags[i].flag;
}
#endif

*enumerator = new_enum;

Expand Down

0 comments on commit 8ac1ea9

Please sign in to comment.