Skip to content

Commit d95c650

Browse files
committed
fixed possible issue in uninstaller where file types without existing handlers could leave ours hanging in the registry added support for long paths to the dll
1 parent 3ba7d7e commit d95c650

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/handler.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ impl PropertyHandler {
136136
}
137137

138138
impl IInitializeWithFile_Impl for PropertyHandler_Impl {
139-
fn Initialize(&self, pszfilepath: &PCWSTR, _grfmode: u32) -> Result<()> {
139+
fn Initialize(&self, pszfilepath: &PCWSTR, grfmode: u32) -> Result<()> {
140+
// Enforce read-only access (STGM_READ is 0; STGM_WRITE=1, STGM_READWRITE=2 are masked by 0x3)
141+
if (grfmode & 0x3) != 0 {
142+
return Err(Error::from(STG_E_ACCESSDENIED));
143+
}
144+
140145
let path_str = unsafe { pszfilepath.to_string()? };
141146
let path = Path::new(&path_str);
142147

src/registry.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ fn get_dll_path() -> Result<String> {
4444
PCWSTR(get_dll_path as *const () as usize as *const u16),
4545
&mut hmod,
4646
)?;
47-
let mut buf = [0u16; 260];
48-
let len = GetModuleFileNameW(hmod, &mut buf);
49-
if len == 0 {
47+
let mut buf = vec![0u16; 32768];
48+
let len = GetModuleFileNameW(hmod, &mut buf[..]);
49+
if len == 0 || len as usize >= buf.len() {
5050
return Err(Error::from_win32());
5151
}
5252
Ok(String::from_utf16_lossy(&buf[..len as usize]))
@@ -315,6 +315,10 @@ pub fn unregister() -> Result<()> {
315315
unsafe {
316316
let _ = RegDeleteValueW(hk, PCWSTR(w.as_ptr()));
317317
}
318+
} else {
319+
unsafe {
320+
let _ = RegDeleteValueW(hk, PCWSTR(core::ptr::null()));
321+
}
318322
}
319323
}
320324
unsafe {

0 commit comments

Comments
 (0)