Skip to content

Commit

Permalink
Add tests to check for negative INOUT length values for name_len and …
Browse files Browse the repository at this point in the history
…desc_len.
  • Loading branch information
cchambreau committed Jun 29, 2022
1 parent f435134 commit 6e8e869
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions events/events_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ int event_info_failed = 0;
int event_info_displacements_start_at_0 = 1;
int event_count_result = 0;
int event_get_num_handle_null = 0;
int event_info_negative_name_len_handled = 1;
int event_info_negative_desc_len_handled = 1;


void print_results() {
Expand All @@ -32,6 +34,8 @@ void print_results() {

if ( do_failure_tests ) {
print_pf_result("MPI_T_event_get_num", "Handle NULL argument", event_get_num_handle_null);
print_pf_result("MPI_T_event_get_info", "Handle negative name length", event_info_negative_name_len_handled);
print_pf_result("MPI_T_event_get_info", "Handle negative desc length", event_info_negative_desc_len_handled);
}

fprintf(outstream, "%-*s - %-*s : %6d\n", func_width, "TOTAL ERROR COUNT", metric_width, "", error_count);
Expand Down Expand Up @@ -199,6 +203,61 @@ void test_get_info() {
}
}


if ( do_failure_tests ) {

int save_name_len;

save_name_len = ci.name_len;

/* name_len and desc_len are INOUT arguments and should handle negative values
* Ideally it would return MPI_ERR_ARG (although not specified in MPI Standard v4.0),
* but otherwise it should at least not segfault.*/
ci.name_len = -100;
print_debug("Testing MPI_T_event_get_info with negative name_len\n");
retval = MPI_T_event_get_info(
ci.event_index,
ci.name,
&(ci.name_len),
&(ci.verbosity),
ci.array_of_datatypes,
ci.array_of_displacements,
&(ci.num_elements),
&(ci.enumtype),
&(ci.info),
ci.desc,
&(ci.desc_len),
&(ci.bind)
) ;

if (MPI_ERR_ARG != retval && 1 == event_info_negative_name_len_handled ) {
event_info_negative_name_len_handled = 0;
}

ci.name_len = save_name_len;
ci.desc_len = -100;

print_debug("Testing MPI_T_event_get_info with negative name_len\n");
retval = MPI_T_event_get_info(
ci.event_index,
ci.name,
&(ci.name_len),
&(ci.verbosity),
ci.array_of_datatypes,
ci.array_of_displacements,
&(ci.num_elements),
&(ci.enumtype),
&(ci.info),
ci.desc,
&(ci.desc_len),
&(ci.bind)
) ;

if (MPI_ERR_ARG != retval && 1 == event_info_negative_desc_len_handled ) {
event_info_negative_desc_len_handled = 0;
}
}

free(ci.name);
free(ci.desc);
free(infos);
Expand Down

0 comments on commit 6e8e869

Please sign in to comment.