From 30d8349c7c180cd01da20d4f99ae0cc7275be87b Mon Sep 17 00:00:00 2001 From: LaxminarayanaV7416 Date: Wed, 27 Aug 2025 19:05:29 -0400 Subject: [PATCH 1/3] Fixed the vine_factory bug during command line submission --- batch_job/src/vine_factory.c | 40 ++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/batch_job/src/vine_factory.c b/batch_job/src/vine_factory.c index fbe7d08dc1..820ade8b5e 100644 --- a/batch_job/src/vine_factory.c +++ b/batch_job/src/vine_factory.c @@ -219,6 +219,34 @@ int manager_workers_capacity(struct jx *j) { return capacity; } +char *shell_escape(const char *input) { + size_t len = strlen(input); + + // Worst case: every char becomes 2 chars + quotes + char *output = malloc(len * 2 + 3); + if (!output) return NULL; + + char *dst = output; + *dst++ = '"'; // open double quote + + for (const char *src = input; *src; src++) { + switch (*src) { + case '"': *dst++ = '\\'; *dst++ = '"'; break; + case '\\': *dst++ = '\\'; *dst++ = '\\'; break; + case '$': *dst++ = '\\'; *dst++ = '$'; break; + case '`': *dst++ = '\\'; *dst++ = '`'; break; + case '!': *dst++ = '\\'; *dst++ = '!'; break; + case '\'': *dst++ = '\\'; *dst++ = '\''; break; // escape single quote + default: *dst++ = *src; break; + } + } + + *dst++ = '"'; // close double quote + *dst = '\0'; + + return output; +} + int manager_workers_needed_by_resource(struct jx *j) { int tasks_total_cores = jx_lookup_integer(j, "tasks_total_cores"); int tasks_total_memory = jx_lookup_integer(j, "tasks_total_memory"); @@ -468,7 +496,7 @@ static int submit_worker( struct batch_queue *queue ) cmd = string_format( "./%s --parent-death -M %s -t %d -C '%s' %s %s %s %s %s %s %s %s", worker_command, - submission_regex, + shell_escape(submission_regex), worker_timeout, catalog_host, debug_workers ? debug_worker_options : "", @@ -484,7 +512,7 @@ static int submit_worker( struct batch_queue *queue ) cmd = string_format( "./%s --parent-death %s %d -t %d -C '%s' %s %s %s %s %s %s %s", worker_command, - manager_host, + shell_escape(manager_host), manager_port, worker_timeout, catalog_host, @@ -1686,7 +1714,9 @@ int main(int argc, char *argv[]) char* cmd; if(worker_command != NULL){ - cmd = string_format("cp '%s' '%s'",worker_command,scratch_dir); + cmd = string_format("cp %s %s", + shell_escape(worker_command), + shell_escape(scratch_dir)); if(system(cmd)){ fprintf(stderr,"vine_factory: Could not Access specified worker binary.\n"); exit(EXIT_FAILURE); @@ -1703,7 +1733,9 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - cmd = string_format("cp '%s' '%s'",tmp,scratch_dir); + cmd = string_format("cp %s %s", + shell_escape(tmp), + shell_escape(scratch_dir)); if (system(cmd)) { fprintf(stderr, "vine_factory: could not copy vine_worker to scratch directory.\n"); exit(EXIT_FAILURE); From adc4c58340d8a22aa2e6064bca19d927a07ea3a0 Mon Sep 17 00:00:00 2001 From: LaxminarayanaV7416 Date: Mon, 1 Sep 2025 00:54:55 -0400 Subject: [PATCH 2/3] made changes as per the btovar request --- batch_job/src/vine_factory.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/batch_job/src/vine_factory.c b/batch_job/src/vine_factory.c index 820ade8b5e..53c6c9ddfd 100644 --- a/batch_job/src/vine_factory.c +++ b/batch_job/src/vine_factory.c @@ -219,7 +219,7 @@ int manager_workers_capacity(struct jx *j) { return capacity; } -char *shell_escape(const char *input) { +char *string_escape_shell(const char *input) { size_t len = strlen(input); // Worst case: every char becomes 2 chars + quotes @@ -496,7 +496,7 @@ static int submit_worker( struct batch_queue *queue ) cmd = string_format( "./%s --parent-death -M %s -t %d -C '%s' %s %s %s %s %s %s %s %s", worker_command, - shell_escape(submission_regex), + string_escape_shell(submission_regex), worker_timeout, catalog_host, debug_workers ? debug_worker_options : "", @@ -512,7 +512,7 @@ static int submit_worker( struct batch_queue *queue ) cmd = string_format( "./%s --parent-death %s %d -t %d -C '%s' %s %s %s %s %s %s %s", worker_command, - shell_escape(manager_host), + string_escape_shell(manager_host), manager_port, worker_timeout, catalog_host, @@ -1715,8 +1715,8 @@ int main(int argc, char *argv[]) char* cmd; if(worker_command != NULL){ cmd = string_format("cp %s %s", - shell_escape(worker_command), - shell_escape(scratch_dir)); + string_escape_shell(worker_command), + string_escape_shell(scratch_dir)); if(system(cmd)){ fprintf(stderr,"vine_factory: Could not Access specified worker binary.\n"); exit(EXIT_FAILURE); @@ -1734,8 +1734,8 @@ int main(int argc, char *argv[]) } cmd = string_format("cp %s %s", - shell_escape(tmp), - shell_escape(scratch_dir)); + string_escape_shell(tmp), + string_escape_shell(scratch_dir)); if (system(cmd)) { fprintf(stderr, "vine_factory: could not copy vine_worker to scratch directory.\n"); exit(EXIT_FAILURE); From 561ba1df3dc0032bb3ed83c7da3a20745d7e03cf Mon Sep 17 00:00:00 2001 From: LaxminarayanaV7416 Date: Mon, 1 Sep 2025 00:59:41 -0400 Subject: [PATCH 3/3] changed the string_escape_shell to string_escape_shell_vine_factory --- batch_job/src/vine_factory.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/batch_job/src/vine_factory.c b/batch_job/src/vine_factory.c index 53c6c9ddfd..3add472434 100644 --- a/batch_job/src/vine_factory.c +++ b/batch_job/src/vine_factory.c @@ -219,7 +219,7 @@ int manager_workers_capacity(struct jx *j) { return capacity; } -char *string_escape_shell(const char *input) { +char *string_escape_shell_vine_factory(const char *input) { size_t len = strlen(input); // Worst case: every char becomes 2 chars + quotes @@ -496,7 +496,7 @@ static int submit_worker( struct batch_queue *queue ) cmd = string_format( "./%s --parent-death -M %s -t %d -C '%s' %s %s %s %s %s %s %s %s", worker_command, - string_escape_shell(submission_regex), + string_escape_shell_vine_factory(submission_regex), worker_timeout, catalog_host, debug_workers ? debug_worker_options : "", @@ -512,7 +512,7 @@ static int submit_worker( struct batch_queue *queue ) cmd = string_format( "./%s --parent-death %s %d -t %d -C '%s' %s %s %s %s %s %s %s", worker_command, - string_escape_shell(manager_host), + string_escape_shell_vine_factory(manager_host), manager_port, worker_timeout, catalog_host, @@ -1715,8 +1715,8 @@ int main(int argc, char *argv[]) char* cmd; if(worker_command != NULL){ cmd = string_format("cp %s %s", - string_escape_shell(worker_command), - string_escape_shell(scratch_dir)); + string_escape_shell_vine_factory(worker_command), + string_escape_shell_vine_factory(scratch_dir)); if(system(cmd)){ fprintf(stderr,"vine_factory: Could not Access specified worker binary.\n"); exit(EXIT_FAILURE); @@ -1734,8 +1734,8 @@ int main(int argc, char *argv[]) } cmd = string_format("cp %s %s", - string_escape_shell(tmp), - string_escape_shell(scratch_dir)); + string_escape_shell_vine_factory(tmp), + string_escape_shell_vine_factory(scratch_dir)); if (system(cmd)) { fprintf(stderr, "vine_factory: could not copy vine_worker to scratch directory.\n"); exit(EXIT_FAILURE);