| 349 | } |
| 350 | |
| 351 | bool cbm_build_win_cmd_payload(char *buf, size_t cap, const char *cmd_executable, |
| 352 | const char *payload) { |
| 353 | if (!buf || cap == 0) { |
| 354 | return false; |
| 355 | } |
| 356 | buf[0] = '\0'; |
| 357 | if (!cbm_win_cmd_path_is_absolute(cmd_executable) || !payload || !payload[0]) { |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | static const char prefix[] = "\" /D /S /V:OFF /C "; |
| 362 | size_t executable_len = strlen(cmd_executable); |
| 363 | size_t payload_len = strlen(payload); |
| 364 | size_t remaining = cap - 1; /* reserve the final NUL */ |
| 365 | if (remaining < 1) { |
| 366 | return false; |
| 367 | } |
| 368 | remaining--; /* opening quote */ |
| 369 | if (executable_len > remaining) { |
| 370 | return false; |
| 371 | } |
| 372 | remaining -= executable_len; |
| 373 | if (sizeof(prefix) - 1 > remaining) { |
| 374 | return false; |
| 375 | } |
| 376 | remaining -= sizeof(prefix) - 1; |
| 377 | if (payload_len > remaining) { |
| 378 | return false; |
| 379 | } |
| 380 | |
| 381 | size_t pos = 0; |
| 382 | buf[pos++] = '"'; |
| 383 | memcpy(buf + pos, cmd_executable, executable_len); |
| 384 | pos += executable_len; |
| 385 | memcpy(buf + pos, prefix, sizeof(prefix) - 1); |
| 386 | pos += sizeof(prefix) - 1; |
| 387 | memcpy(buf + pos, payload, payload_len); |
| 388 | pos += payload_len; |
| 389 | buf[pos] = '\0'; |
| 390 | return true; |
| 391 | } |
| 392 | |
| 393 | /* ── Nonblocking contained-process supervisor ─────────────────────────────── */ |
| 394 |
no test coverage detected