Build a full Windows CreateProcess command line from a NULL-terminated argv, * applying the MS C runtime quoting rules so the child re-parses byte-identical * argv. Returns true on success, false if the result would overflow `buf`. * * Defined unconditionally (pure string logic, no Windows headers) so the quoting * contract is unit-tested on Linux/macOS CI too — even though the real spawn pat
| 208 | * containing a quote (e.g. the index JSON {"repo_path":"…"}), corrupting the |
| 209 | * spawned child's argv. */ |
| 210 | bool cbm_build_win_cmdline(char *buf, size_t cap, const char *const *argv) { |
| 211 | if (!buf || cap == 0 || !argv) { |
| 212 | return false; |
| 213 | } |
| 214 | size_t pos = 0; |
| 215 | bool ovf = false; |
| 216 | for (int i = 0; argv[i]; i++) { |
| 217 | pos = cbm_cmdline_append_arg(buf, cap, pos, argv[i], i == 0, &ovf); |
| 218 | if (ovf) { |
| 219 | buf[0] = '\0'; /* overflow: leave buf a valid (empty) string, never unterminated */ |
| 220 | return false; |
| 221 | } |
| 222 | } |
| 223 | buf[pos] = '\0'; |
| 224 | return true; |
| 225 | } |
| 226 | |
| 227 | #ifdef _WIN32 |
| 228 |