Skip to content

Commit

Permalink
prte.c: a prefix of "/" is ok
Browse files Browse the repository at this point in the history
It's not an error if the prefix ends up being a plain "/".  More
specifically, if we strip off all trailing "/" characters from the
prefix and end up with an empty string, then the prefix is just "/".

Protect against a NULL prefix being added to the app's attributes.

Protect against a double-/ in the prted cmd path in the ssh
launch component.

Signed-off-by: Jeff Squyres <[email protected]>
Signed-off-by: Ralph Castain <[email protected]>
  • Loading branch information
rhc54 authored and jsquyres committed Nov 17, 2023
1 parent 361592b commit ce7f686
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/mca/plm/ssh/plm_ssh_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Copyright (c) 2014-2020 Intel, Inc. All rights reserved.
* Copyright (c) 2015-2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2021-2022 Nanook Consulting. All rights reserved.
* Copyright (c) 2021-2023 Nanook Consulting. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -592,7 +592,11 @@ static int setup_launch(int *argcptr, char ***argvptr, char *nodename, int *node
if (0 == strcmp(orted_cmd, "prted")) {
/* if the cmd is our standard one, then add the prefix */
value = pmix_basename(prte_install_dirs.bindir);
pmix_asprintf(&tmp, "%s/%s", prefix_dir, value);
if ('/' == prefix_dir[strlen(prefix_dir)-1]) {
pmix_asprintf(&tmp, "%s%s", prefix_dir, value);
} else {
pmix_asprintf(&tmp, "%s/%s", prefix_dir, value);
}
free(value);
pmix_asprintf(&full_orted_cmd, "%s/%s", tmp, orted_cmd);
free(tmp);
Expand Down
14 changes: 8 additions & 6 deletions src/tools/prte/prte.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* reserved.
* Copyright (c) 2022-2023 Triad National Security, LLC. All rights
* reserved.
* Copyright (c) 2023 Jeffrey M. Squyres. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -704,14 +705,15 @@ int main(int argc, char *argv[])
param[param_len - 1] = '\0';
param_len--;
if (0 == param_len) {
pmix_show_help("help-prun.txt", "prun:empty-prefix", true, prte_tool_basename,
prte_tool_basename);
PRTE_UPDATE_EXIT_STATUS(PRTE_ERR_FATAL);
goto DONE;
/* We get here if we removed all PATH_SEP's and end up
with an empty string. In this case, the prefix is
just a single PATH_SEP. */
strncpy(param, PRTE_PATH_SEP, sizeof(param) - 1);
break;
}
}
prte_set_attribute(&dapp->attributes, PRTE_APP_PREFIX_DIR, PRTE_ATTR_GLOBAL, param,
PMIX_STRING);
prte_set_attribute(&dapp->attributes, PRTE_APP_PREFIX_DIR, PRTE_ATTR_GLOBAL,
param, PMIX_STRING);
free(param);
} else {
/* Check if called with fully-qualified path to prte.
Expand Down

0 comments on commit ce7f686

Please sign in to comment.