diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2025-06-10 13:02:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-10 13:02:49 -0400 |
commit | 960f50e822b27ae6cff180ad66ce98e59c2476d4 (patch) | |
tree | be94ff3ca932931c70f6bb241a4367c4aac3015a | |
parent | b99daf7d16227f9dc9197699d7b24d2373fa5219 (diff) | |
parent | 31bea62c83a260e33a2b282d9b2da19ef264de0d (diff) | |
download | stasis-960f50e822b27ae6cff180ad66ce98e59c2476d4.tar.gz |
Merge pull request #107 from jhunkeler/pip-dynamic
pip: dynamically allocate command based on length
-rw-r--r-- | src/lib/core/conda.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c index c81e6cc..44af34d 100644 --- a/src/lib/core/conda.c +++ b/src/lib/core/conda.c @@ -62,17 +62,39 @@ int micromamba(struct MicromambaInfo *info, char *command, ...) { } int python_exec(const char *args) { - char command[PATH_MAX] = {0}; - snprintf(command, sizeof(command) - 1, "python %s", args); + int result = -1; + const char *command_base = "python "; + const size_t required_len = strlen(command_base) + strlen(args) + 1; + + char *command = calloc(required_len, sizeof(*command)); + if (!command) { + SYSERROR("Unable to allocate %zu bytes for command string", required_len); + return result; + } + snprintf(command, required_len, "%s%s", command_base, args); msg(STASIS_MSG_L3, "Executing: %s\n", command); - return system(command); + + result = system(command); + guard_free(command); + return result; } int pip_exec(const char *args) { - char command[PATH_MAX] = {0}; - snprintf(command, sizeof(command) - 1, "python -m pip %s", args); + int result = -1; + const char *command_base = "python -m pip "; + const size_t required_len = strlen(command_base) + strlen(args) + 1; + + char *command = calloc(required_len, sizeof(*command)); + if (!command) { + SYSERROR("Unable to allocate %zu bytes for command string", required_len); + return result; + } + snprintf(command, required_len, "%s%s", command_base, args); msg(STASIS_MSG_L3, "Executing: %s\n", command); - return system(command); + + result = system(command); + guard_free(command); + return result; } static const char *PKG_ERROR_STR[] = { |