Skip to content

Commit 53b03b0

Browse files
committed
full-cmd: do not use stack
1 parent 34732ff commit 53b03b0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/stdlib_system_subprocess.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,26 @@ void process_create_windows(const char* cmd, const char* stdin_stream,
9292
si.dwFlags |= STARTF_USESTDHANDLES;
9393

9494
// Prepare the command line with redirected stdin
95-
char full_cmd[4096];
95+
char* full_cmd;
96+
size_t cmd_len = strlen(cmd);
97+
size_t stdin_len = stdin_file ? strlen(stdin_file) : 0;
98+
size_t full_cmd_len = cmd_len + stdin_len + 5;
99+
full_cmd = (char*)malloc(full_cmd_len);
100+
if (!full_cmd) {
101+
fprintf(stderr, "Failed to allocate memory for full_cmd\n");
102+
return;
103+
}
104+
105+
// Use full_cmd as needed (e.g., pass to CreateProcess)
96106
if (stdin_file) {
97-
snprintf(full_cmd, sizeof(full_cmd), "%s < %s", cmd, stdin_file);
107+
snprintf(full_cmd, full_cmd_len, "%s < %s", cmd, stdin_file);
98108
} else {
99-
snprintf(full_cmd, sizeof(full_cmd), "%s", cmd);
109+
snprintf(full_cmd, full_cmd_len, "%s", cmd);
100110
}
101111

112+
// Free the allocated memory
113+
free(full_cmd);
114+
102115
// Create the process
103116
BOOL success = CreateProcess(
104117
NULL, // Application name

0 commit comments

Comments
 (0)