MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_resolve_comspec

Function cbm_resolve_comspec

src/foundation/compat_fs.c:179–191  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

177 * can be passed as lpApplicationName and CreateProcess never walks the search
178 * path (no cmd.exe planting from a hostile CWD). Heap string; caller frees. */
179static wchar_t *cbm_resolve_comspec(void) {
180 wchar_t buf[MAX_PATH];
181 const wchar_t suffix[] = L"\\cmd.exe";
182 DWORD n = GetEnvironmentVariableW(L"COMSPEC", buf, MAX_PATH);
183 if (n == 0 || n >= MAX_PATH) {
184 UINT sn = GetSystemDirectoryW(buf, MAX_PATH);
185 if (sn == 0 || (size_t)sn + wcslen(suffix) >= MAX_PATH) {
186 return NULL;
187 }
188 wmemcpy(buf + sn, suffix, wcslen(suffix) + 1);
189 }
190 return _wcsdup(buf);
191}
192
193/* On failure returns NULL with *stage naming the failing step and *gle the
194 * GetLastError value captured at that step (0 when errno is the signal). */

Callers 1

cbm_popen_isolatedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected