Skip to content

Commit 6e8e869

Browse files
committed
Add tests to check for negative INOUT length values for name_len and desc_len.
1 parent f435134 commit 6e8e869

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

Diff for: events/events_types.c

+59
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ int event_info_failed = 0;
1717
int event_info_displacements_start_at_0 = 1;
1818
int event_count_result = 0;
1919
int event_get_num_handle_null = 0;
20+
int event_info_negative_name_len_handled = 1;
21+
int event_info_negative_desc_len_handled = 1;
2022

2123

2224
void print_results() {
@@ -32,6 +34,8 @@ void print_results() {
3234

3335
if ( do_failure_tests ) {
3436
print_pf_result("MPI_T_event_get_num", "Handle NULL argument", event_get_num_handle_null);
37+
print_pf_result("MPI_T_event_get_info", "Handle negative name length", event_info_negative_name_len_handled);
38+
print_pf_result("MPI_T_event_get_info", "Handle negative desc length", event_info_negative_desc_len_handled);
3539
}
3640

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

206+
207+
if ( do_failure_tests ) {
208+
209+
int save_name_len;
210+
211+
save_name_len = ci.name_len;
212+
213+
/* name_len and desc_len are INOUT arguments and should handle negative values
214+
* Ideally it would return MPI_ERR_ARG (although not specified in MPI Standard v4.0),
215+
* but otherwise it should at least not segfault.*/
216+
ci.name_len = -100;
217+
print_debug("Testing MPI_T_event_get_info with negative name_len\n");
218+
retval = MPI_T_event_get_info(
219+
ci.event_index,
220+
ci.name,
221+
&(ci.name_len),
222+
&(ci.verbosity),
223+
ci.array_of_datatypes,
224+
ci.array_of_displacements,
225+
&(ci.num_elements),
226+
&(ci.enumtype),
227+
&(ci.info),
228+
ci.desc,
229+
&(ci.desc_len),
230+
&(ci.bind)
231+
) ;
232+
233+
if (MPI_ERR_ARG != retval && 1 == event_info_negative_name_len_handled ) {
234+
event_info_negative_name_len_handled = 0;
235+
}
236+
237+
ci.name_len = save_name_len;
238+
ci.desc_len = -100;
239+
240+
print_debug("Testing MPI_T_event_get_info with negative name_len\n");
241+
retval = MPI_T_event_get_info(
242+
ci.event_index,
243+
ci.name,
244+
&(ci.name_len),
245+
&(ci.verbosity),
246+
ci.array_of_datatypes,
247+
ci.array_of_displacements,
248+
&(ci.num_elements),
249+
&(ci.enumtype),
250+
&(ci.info),
251+
ci.desc,
252+
&(ci.desc_len),
253+
&(ci.bind)
254+
) ;
255+
256+
if (MPI_ERR_ARG != retval && 1 == event_info_negative_desc_len_handled ) {
257+
event_info_negative_desc_len_handled = 0;
258+
}
259+
}
260+
202261
free(ci.name);
203262
free(ci.desc);
204263
free(infos);

0 commit comments

Comments
 (0)