-
Notifications
You must be signed in to change notification settings - Fork 124
Fixed the vine_factory bug during command line submission #4235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,6 +219,34 @@ int manager_workers_capacity(struct jx *j) { | |
| return capacity; | ||
| } | ||
|
|
||
| char *string_escape_shell_vine_factory(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, | ||
| string_escape_shell_vine_factory(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, | ||
| string_escape_shell_vine_factory(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", | ||
| 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); | ||
|
|
@@ -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", | ||
| string_escape_shell_vine_factory(tmp), | ||
| string_escape_shell_vine_factory(scratch_dir)); | ||
|
Comment on lines
+1737
to
+1738
|
||
| if (system(cmd)) { | ||
| fprintf(stderr, "vine_factory: could not copy vine_worker to scratch directory.\n"); | ||
| exit(EXIT_FAILURE); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memory allocation calculation
len * 2 + 3may be insufficient for strings containing many special characters. Consider using a more conservative calculation or dynamic reallocation to prevent buffer overflows.