Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions opal/mca/btl/uct/btl_uct_discover.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,24 +419,19 @@ int mca_btl_uct_component_maybe_setup_conn_tl(void)

mca_btl_uct_md_t *md;
OPAL_LIST_FOREACH(md, &mca_btl_uct_component.md_list, mca_btl_uct_md_t) {
mca_btl_uct_tl_t *tl, *next;
OPAL_LIST_FOREACH_SAFE(tl, next, &md->tls, mca_btl_uct_tl_t) {
mca_btl_uct_tl_t *tl;
OPAL_LIST_FOREACH(tl, &md->tls, mca_btl_uct_tl_t) {
if (mca_btl_uct_tl_supports_conn(tl)) {
break;
}
tl = NULL;
}

if ((opal_list_item_t *) tl == &md->tls.opal_list_sentinel) {
BTL_VERBOSE(("No suitable connection tls in md %s", md->md_name));
continue;
}

if (NULL == mca_btl_uct_component.conn_tl) {
mca_btl_uct_component.conn_tl = tl;
}

if (tl != NULL && (md->connection_only_domain || NULL == mca_btl_uct_component.conn_tl)) {
if (md->connection_only_domain || NULL == mca_btl_uct_component.conn_tl) {
mca_btl_uct_component.conn_tl = tl;
if (md->connection_only_domain) {
/* not going do to better */
Expand Down
4 changes: 2 additions & 2 deletions opal/mca/btl/uct/btl_uct_modex.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static uint8_t *mca_btl_uct_tl_modex_pack(mca_btl_uct_module_t *module, mca_btl_
tl_modex->size = mca_btl_uct_tl_modex_size(tl);

memset(tl_modex->tl_name, 0, sizeof(tl_modex->tl_name));
strncpy(tl_modex->tl_name, tl->uct_tl_name, sizeof(tl_modex->tl_name));
strncpy(tl_modex->tl_name, tl->uct_tl_name, sizeof(tl_modex->tl_name) - 1);

uint8_t *tl_modex_data = (uint8_t *) tl_modex->data;

Expand Down Expand Up @@ -107,7 +107,7 @@ static uint8_t *mca_btl_uct_modex_pack(mca_btl_uct_md_t *md, uint8_t *modex_data
md_modex->module_index = module ? module->module_index : (uint16_t) -1;

memset(md_modex->md_name, 0, sizeof(md_modex->md_name));
strncpy(md_modex->md_name, md->md_name, sizeof(md_modex->md_name));
strncpy(md_modex->md_name, md->md_name, sizeof(md_modex->md_name) - 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why -1 ? It makes no sense because how do you ensure there is a \0 at the end ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the documentation.

No null-character is implicitly appended at the end of destination if source is longer than num. Thus, in this case, destination shall not be considered a null terminated C string (reading it as such would overflow).

So, by reducing the size by 1 it ensures the \0 written by the memset above it does not get overwritten by the strncpy().

Copy link
Member

@bosilca bosilca Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the defensive programming approach, but all this cannot happen here, because of "context", something that coverity does not understand/handle. The modex string is of correct size because it was put there by another of the OMPI processes, so it already correct and includes the ending \0 in all cases, which means it works properly all the time. If we are concerned about incorrect modex information, or hacking tentative via the modex that's another story, but that's yet another story that cannot be fixed by just this patch.


mca_btl_uct_tl_t *tl;
OPAL_LIST_FOREACH(tl, &md->tls, mca_btl_uct_tl_t) {
Expand Down
14 changes: 9 additions & 5 deletions opal/mca/btl/uct/btl_uct_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,15 @@ int mca_btl_uct_finalize(mca_btl_base_module_t *btl)
OBJ_DESTRUCT(&uct_module->endpoint_lock);

char *tmp;
asprintf(&tmp, "uct_%s", uct_module->md->md_name);
int rc = mca_base_var_group_find("opal", "btl", tmp);
free(tmp);
if (rc >= 0) {
mca_base_var_group_deregister(rc);
int rc = asprintf(&tmp, "uct_%s", uct_module->md->md_name);
if (rc > 0) {
rc = mca_base_var_group_find("opal", "btl", tmp);
free(tmp);
if (rc >= 0) {
mca_base_var_group_deregister(rc);
}
} else {
BTL_ERROR(("could not deregister var group for UCT module %s", uct_module->md->md_name));
}

OBJ_RELEASE(uct_module->md);
Expand Down