Skip to content

Commit 791b25d

Browse files
committed
fix(installer): prevent destructive PATH overwrite on registry read error
Replace unwrap_or_default() with explicit error matching: only treat ERROR_FILE_NOT_FOUND as empty PATH (fresh user with no custom PATH). Any other error (corrupt data, wrong type, permission issue) is now propagated, preventing the installer from silently replacing the user's entire PATH with just the vp bin directory.
1 parent bfaa80f commit 791b25d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

crates/vite_installer/src/windows_path.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ pub fn add_to_user_path(bin_dir: &str) -> io::Result<()> {
4848
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
4949
let env = hkcu.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)?;
5050

51-
let current: String = env.get_value("Path").unwrap_or_default();
51+
// Only treat "value not found" as empty PATH. Any other error (corrupt
52+
// data, wrong type) must be propagated to avoid overwriting the user's PATH.
53+
let current: String = match env.get_value("Path") {
54+
Ok(val) => val,
55+
Err(e) if e.raw_os_error() == Some(2) => String::new(), // ERROR_FILE_NOT_FOUND
56+
Err(e) => return Err(e),
57+
};
5258
let bin_dir_normalized = bin_dir.trim_end_matches('\\');
5359

5460
let already_present = current

0 commit comments

Comments
 (0)