Skip to content

Commit 44acc92

Browse files
mkurnosovggouaillardet
authored andcommitted
Fix buffer overflow
Add check for bounds of sindex[] and rindex[]. Signed-off-by: Mikhail Kurnosov <[email protected]>
1 parent 5fceca2 commit 44acc92

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

ompi/mca/coll/spacc/coll_spacc_allreduce.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,12 @@ int mca_coll_spacc_allreduce_intra_redscat_allgather(
276276
rcount[step], dtype);
277277

278278
/* Move the current window to the received message */
279-
rindex[step + 1] = rindex[step];
280-
sindex[step + 1] = rindex[step];
281-
wsize = rcount[step];
282-
step++;
279+
if (step + 1 < nsteps) {
280+
rindex[step + 1] = rindex[step];
281+
sindex[step + 1] = rindex[step];
282+
wsize = rcount[step];
283+
step++;
284+
}
283285
}
284286
/*
285287
* Assertion: each process has 1 / p' of the total reduction result:

ompi/mca/coll/spacc/coll_spacc_reduce.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,12 @@ int mca_coll_spacc_reduce_intra_redscat_gather(
291291
rcount[step], dtype);
292292

293293
/* Move the current window to the received message */
294-
rindex[step + 1] = rindex[step];
295-
sindex[step + 1] = rindex[step];
296-
wsize = rcount[step];
297-
step++;
294+
if (step + 1 < nsteps) {
295+
rindex[step + 1] = rindex[step];
296+
sindex[step + 1] = rindex[step];
297+
wsize = rcount[step];
298+
step++;
299+
}
298300
}
299301
}
300302
/*

0 commit comments

Comments
 (0)