From 039b7acfb578abb012fbffb9953fdaab5473fa71 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Fri, 22 Aug 2014 22:47:38 +0000 Subject: [PATCH] Fix the quoting algorithm so only rsh command lines get quoted values cmr=v1.8.2:reviewer=jsquyres This commit was SVN r32586. --- orte/mca/plm/base/plm_base_launch_support.c | 20 ++++------ orte/mca/plm/rsh/plm_rsh_module.c | 44 +++++++++------------ 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/orte/mca/plm/base/plm_base_launch_support.c b/orte/mca/plm/base/plm_base_launch_support.c index 919e1ebaf3..6002fb0060 100644 --- a/orte/mca/plm/base/plm_base_launch_support.c +++ b/orte/mca/plm/base/plm_base_launch_support.c @@ -1173,19 +1173,18 @@ int orte_plm_base_orted_append_basic_args(int *argc, char ***argv, if (ORTE_PROC_IS_HNP) { rml_uri = orte_rml.get_contact_info(); } else { - asprintf(¶m, "\"%s\"", orte_rml.get_contact_info() ); + rml_uri = orte_rml.get_contact_info(); opal_argv_append(argc, argv, "-mca"); opal_argv_append(argc, argv, "orte_parent_uri"); - opal_argv_append(argc, argv, param); - free(param); + opal_argv_append(argc, argv, rml_uri); + free(rml_uri); - rml_uri = orte_process_info.my_hnp_uri; + rml_uri = strdup(orte_process_info.my_hnp_uri); } - asprintf(¶m, "\"%s\"", rml_uri); opal_argv_append(argc, argv, "-mca"); opal_argv_append(argc, argv, "orte_hnp_uri"); - opal_argv_append(argc, argv, param); - free(param); + opal_argv_append(argc, argv, rml_uri); + free(rml_uri); /* if we have static ports, pass the node list */ if (orte_static_ports && NULL != nodes) { @@ -1304,15 +1303,10 @@ int orte_plm_base_orted_append_basic_args(int *argc, char ***argv, } } if (!ignore) { - /* even if it is a single word, we have to try and quote it - * because it could contain a special character like a colon - * or semicolon */ - (void)asprintf(&tmp_force, "\"%s\"", orted_cmd_line[i+2]); /* pass it along */ opal_argv_append(argc, argv, orted_cmd_line[i]); opal_argv_append(argc, argv, orted_cmd_line[i+1]); - opal_argv_append(argc, argv, tmp_force); - free(tmp_force); + opal_argv_append(argc, argv, orted_cmd_line[i+2]); } } } diff --git a/orte/mca/plm/rsh/plm_rsh_module.c b/orte/mca/plm/rsh/plm_rsh_module.c index ceaba38e30..6ea934ddbb 100644 --- a/orte/mca/plm/rsh/plm_rsh_module.c +++ b/orte/mca/plm/rsh/plm_rsh_module.c @@ -335,7 +335,7 @@ static int setup_launch(int *argcptr, char ***argvptr, char *orted_cmd, *orted_prefix, *final_cmd; int orted_index; int rc; - int cnt, i, j; + int i, j; bool found; /* Figure out the basenames for the libdir and bindir. This @@ -566,25 +566,6 @@ static int setup_launch(int *argcptr, char ***argvptr, opal_argv_append_nosize(&argv, "plm"); opal_argv_append_nosize(&argv, "rsh"); - /* in the rsh environment, we can append multi-word arguments - * by enclosing them in quotes. Check for any multi-word - * mca params passed to mpirun and include them - they were - * excluded in append_basic_args - */ - cnt = opal_argv_count(orted_cmd_line); - for (i=0; i < cnt; i+=3) { - if (NULL == strchr(orted_cmd_line[i+2], ' ')) { - continue; - } - /* protect the value with quotes */ - (void)asprintf(¶m, "\"%s\"", orted_cmd_line[i+2]); - /* now pass it along */ - opal_argv_append(&argc, &argv, orted_cmd_line[i]); - opal_argv_append(&argc, &argv, orted_cmd_line[i+1]); - opal_argv_append(&argc, &argv, param); - free(param); - } - /* unless told otherwise... */ if (mca_plm_rsh_component.pass_environ_mca_params) { /* now check our local environment for MCA params - add them @@ -611,19 +592,32 @@ static int setup_launch(int *argcptr, char ***argvptr, } } if (!found) { - char *p2; /* add it */ opal_argv_append(&argc, &argv, "-mca"); opal_argv_append(&argc, &argv, param); - (void)asprintf(&p2, "\"%s\"", value); - opal_argv_append(&argc, &argv, p2); - free(p2); + opal_argv_append(&argc, &argv, value); } free(param); } } } - + + /* in the rsh environment, we need to protect args in quotes + * as they can contain spaces or special characters */ + for (i=0; NULL != argv[i]; i++) { + if (0 != strcmp(argv[i], "-mca")) { + continue; + } + /* protect the value with quotes if not already + * quoted */ + if ('\"' == argv[i+2][0]) { + continue; + } + (void)asprintf(¶m, "\"%s\"", argv[i+2]); + free(argv[i+2]); + argv[i+2] = param; + } + value = opal_argv_join(argv, ' '); if (sysconf(_SC_ARG_MAX) < (int)strlen(value)) { orte_show_help("help-plm-rsh.txt", "cmd-line-too-long",