From fa866037b03afce212a6933d1cd5af148ceab631 Mon Sep 17 00:00:00 2001 From: David Wootton Date: Wed, 12 Oct 2022 16:41:39 -0400 Subject: [PATCH] Fix 1 byte overlay in com_method_string: Coverity CID 1515829 Signed-off-by: David Wootton (cherry picked from commit 3fcad0ecf1dd703f8ef7c110903873336b167c6e) --- ompi/mca/hook/comm_method/hook_comm_method_fns.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ompi/mca/hook/comm_method/hook_comm_method_fns.c b/ompi/mca/hook/comm_method/hook_comm_method_fns.c index 04d964fb18f..bf5e570cc8c 100644 --- a/ompi/mca/hook/comm_method/hook_comm_method_fns.c +++ b/ompi/mca/hook/comm_method/hook_comm_method_fns.c @@ -126,12 +126,14 @@ comm_method_string(MPI_Comm comm, int rank, int *comm_mode) { else { /* Determine how much memory is needed to store UCX transport info */ char *s = UCX_TAG; - name_length = strlen(s); + /* Allocate storage to store UCX transport info, accounting for + * trailing '\0' in UCX_TAG and ',' and ';' delimiting each transport string + * then build the info string */ + name_length = strlen(s) + 1; for (i = 0; i < transports->count; i++) { name_length = name_length + strlen(transports->entries[i].transport_name) + strlen(transports->entries[i].device_name) + 2; } - /* Allocate storage to store UCX transport info then build the info string */ string = malloc(name_length); if (!string) { return NULL;