Resolve the shell explicitly — %COMSPEC%, else \cmd.exe — so it * can be passed as lpApplicationName and CreateProcess never walks the search * path (no cmd.exe planting from a hostile CWD). Heap string; caller frees. */
| 222 | * can be passed as lpApplicationName and CreateProcess never walks the search |
| 223 | * path (no cmd.exe planting from a hostile CWD). Heap string; caller frees. */ |
| 224 | static wchar_t *cbm_resolve_comspec(void) { |
| 225 | wchar_t buf[MAX_PATH]; |
| 226 | const wchar_t suffix[] = L"\\cmd.exe"; |
| 227 | DWORD n = GetEnvironmentVariableW(L"COMSPEC", buf, MAX_PATH); |
| 228 | if (n == 0 || n >= MAX_PATH) { |
| 229 | UINT sn = GetSystemDirectoryW(buf, MAX_PATH); |
| 230 | if (sn == 0 || (size_t)sn + wcslen(suffix) >= MAX_PATH) { |
| 231 | return NULL; |
| 232 | } |
| 233 | wmemcpy(buf + sn, suffix, wcslen(suffix) + 1); |
| 234 | } |
| 235 | return _wcsdup(buf); |
| 236 | } |
| 237 | |
| 238 | /* On failure returns NULL with *stage naming the failing step and *gle the |
| 239 | * GetLastError value captured at that step (0 when errno is the signal). */ |
no outgoing calls
no test coverage detected