Use the existing supervisor with argv, never a shell. Raw NUL-delimited Git * output is read after the child exits: line callbacks cannot represent a path * containing a newline. Output and total wall time both have explicit bounds. */
| 225 | * output is read after the child exits: line callbacks cannot represent a path |
| 226 | * containing a newline. Output and total wall time both have explicit bounds. */ |
| 227 | static char *ia_git(const char *root, const char *const *args, size_t *size, time_t deadline, |
| 228 | bool *bounded) { |
| 229 | *size = 0; |
| 230 | if (time(NULL) >= deadline) { |
| 231 | *bounded = true; |
| 232 | return NULL; |
| 233 | } |
| 234 | const char *git = "git"; |
| 235 | #ifdef _WIN32 |
| 236 | /* CreateProcess needs an executable path; it does not resolve a bare |
| 237 | * application name through PATH. Keep the resolver's result locally. */ |
| 238 | char git_path[1024]; |
| 239 | const char *resolved = cbm_find_cli("git", NULL); |
| 240 | if (!resolved || !*resolved || strlen(resolved) >= sizeof(git_path)) |
| 241 | return NULL; |
| 242 | snprintf(git_path, sizeof(git_path), "%s", resolved); |
| 243 | git = git_path; |
| 244 | #endif |
| 245 | char dir[256] = "/tmp/cbm-impact-XXXXXX"; |
| 246 | if (!cbm_mkdtemp(dir)) |
| 247 | return NULL; |
| 248 | char log[512]; |
| 249 | snprintf(log, sizeof(log), "%s/output", dir); |
| 250 | /* Git before 2.44 rejects --no-lazy-fetch. The environment form is safe |
| 251 | * to pass to older Git; an empty protocol allowlist also denies every |
| 252 | * fetch transport, even when repository configuration enables one. */ |
| 253 | const char *const git_env[] = {"GIT_NO_LAZY_FETCH=1", |
| 254 | "GIT_ALLOW_PROTOCOL=", "GIT_TERMINAL_PROMPT=0", NULL}; |
| 255 | const char *argv[40] = {git, "--no-optional-locks", |
| 256 | "-c", "protocol.allow=never", |
| 257 | "-c", "core.fsmonitor=false", |
| 258 | "-c", "core.untrackedCache=false", |
| 259 | "-C", root}; |
| 260 | int n = 10; |
| 261 | while (*args && n < 39) |
| 262 | argv[n++] = *args++; |
| 263 | argv[n] = NULL; |
| 264 | cbm_proc_opts_t opts = {.bin = git, |
| 265 | .argv = argv, |
| 266 | .env_overrides = git_env, |
| 267 | .strip_git_repo_env = true, |
| 268 | .log_file = log, |
| 269 | .quiet_timeout_ms = 2000, |
| 270 | .cancel_grace_ms = 100}; |
| 271 | cbm_subprocess_t *process = NULL; |
| 272 | cbm_proc_result_t result = {0}; |
| 273 | char *output = NULL; |
| 274 | if (cbm_subprocess_spawn(&opts, &process) != 0) |
| 275 | goto cleanup; |
| 276 | cbm_proc_poll_t poll; |
| 277 | while ((poll = cbm_subprocess_poll(process, &result)) == CBM_PROC_POLL_RUNNING) { |
| 278 | if (time(NULL) >= deadline || cbm_file_size(log) > IA_OUTPUT_CAP) { |
| 279 | *bounded = true; |
| 280 | cbm_subprocess_request_cancel(process); |
| 281 | } |
| 282 | cbm_usleep(10000); |
| 283 | } |
| 284 | if (poll != CBM_PROC_POLL_TERMINAL || result.outcome != CBM_PROC_CLEAN || |
no test coverage detected