Skip to content

Commit

Permalink
Harden reg-free class activation (#3365)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Dec 9, 2024
1 parent f79d13d commit b2ce31d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions crates/libs/core/src/imp/com_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,6 @@ impl IWeakReferenceSource_Vtbl {
}
impl windows_core::RuntimeName for IWeakReferenceSource {}
pub const JSCRIPT_E_CANTEXECUTE: windows_core::HRESULT = windows_core::HRESULT(0x89020001_u32 as _);
pub const REGDB_E_CLASSNOTREG: windows_core::HRESULT = windows_core::HRESULT(0x80040154_u32 as _);
pub const RPC_E_DISCONNECTED: windows_core::HRESULT = windows_core::HRESULT(0x80010108_u32 as _);
pub const TYPE_E_TYPEMISMATCH: windows_core::HRESULT = windows_core::HRESULT(0x80028CA0_u32 as _);
18 changes: 11 additions & 7 deletions crates/libs/core/src/imp/factory_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ pub fn factory<C: crate::RuntimeName, I: Interface>() -> crate::Result<I> {
// can ultimately return this error information if all else fails.
let original: crate::Error = code.into();

// Now attempt to find the factory's implementation heuristically.
if let Some(i) = search_path(C::NAME, |library| unsafe {
get_activation_factory(library, &name)
}) {
i.cast()
} else {
Err(original)
// Reg-free activation should only be attempted if the class is not registered.
// It should not be attempted if the class is registered but fails to activate.
if code == REGDB_E_CLASSNOTREG {
// Now attempt to find the factory's implementation heuristically.
if let Some(i) = search_path(C::NAME, |library| unsafe {
get_activation_factory(library, &name)
}) {
return i.cast();
}
}

Err(original)
}

// Remove the suffix until a match is found appending `.dll\0` at the end
Expand Down
1 change: 1 addition & 0 deletions crates/tools/bindings/src/core_com.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

--filter
Windows.Win32.Foundation.CO_E_NOTINITIALIZED
Windows.Win32.Foundation.REGDB_E_CLASSNOTREG
Windows.Win32.Foundation.E_BOUNDS
Windows.Win32.Foundation.E_INVALIDARG
Windows.Win32.Foundation.E_NOINTERFACE
Expand Down

0 comments on commit b2ce31d

Please sign in to comment.