Skip to content

Commit bd7cef7

Browse files
authored
fix(core): avoid spawning cmd for Windows prompt env (#34)
Verified locally before merge: cargo check --package claurst-core --lib; rg confirmed no cmd /c ver pattern remains in system_prompt.rs; git diff --check origin/main...HEAD. rustfmt --edition 2021 --check src-rust/crates/core/src/system_prompt.rs still reports pre-existing broad formatting churn outside this patch, so it is not treated as a blocker. Co-authored-by: Nova <nova@openclaw.ai>
1 parent 216a193 commit bd7cef7

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

src-rust/crates/core/src/system_prompt.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -352,20 +352,21 @@ fn build_env_info_section(working_dir: Option<&str>) -> String {
352352
let os_version = {
353353
#[cfg(target_os = "windows")]
354354
{
355-
// Read ProductName from the registry via `ver` or env vars.
356-
// Also include architecture for clarity.
357-
let ver = std::process::Command::new("cmd")
358-
.args(["/c", "ver"])
359-
.output()
360-
.ok()
361-
.and_then(|o| String::from_utf8(o.stdout).ok())
362-
.map(|s| s.trim().to_string())
363-
.filter(|s| !s.is_empty());
364-
let arch = std::env::var("PROCESSOR_ARCHITECTURE").unwrap_or_default();
365-
match ver {
366-
Some(v) => format!("{} ({})", v, arch),
367-
None => format!("Windows ({})", arch),
368-
}
355+
// Avoid spawning command processors while constructing the prompt:
356+
// the current working directory may be an untrusted repository.
357+
let os_name = std::env::var("OS")
358+
.ok()
359+
.map(|s| s.trim().to_string())
360+
.filter(|s| !s.is_empty())
361+
.unwrap_or_else(|| "Windows".to_string());
362+
let arch = std::env::var("PROCESSOR_ARCHITECTURE")
363+
.ok()
364+
.map(|s| s.trim().to_string())
365+
.filter(|s| !s.is_empty());
366+
match arch {
367+
Some(arch) => format!("{} ({})", os_name, arch),
368+
None => os_name,
369+
}
369370
}
370371
#[cfg(not(target_os = "windows"))]
371372
{

0 commit comments

Comments
 (0)