Rust advisories / derive-com-impl
Vulnerability MediumRUSTSEC-2021-0083 · derive-com-impl
RUSTSEC-2021-0083: QueryInterface should call AddRef before returning pointer
Short answerA security vulnerability in the derive-com-impl crate: QueryInterface should call AddRef before returning pointer. GitHub rates it Medium. Fixed in 0.1.2: update to a fixed version.
| Crate | derive-com-impl |
|---|---|
| Type | Vulnerability (memory-corruption) |
| Affected versions | Before 0.1.2. |
| Fixed in | 0.1.2 |
| Severity | Medium (GitHub rating) |
| Published | 2021-01-20 |
| Last changed | 2023-11-08 |
| Also known as | CVE-2021-45681, GHSA-9rg7-3j4f-cf4x, GHSA-w4cc-pc2h-whcj |
| Affected functions | derive_com_impl::derive_com_impl |
What to do
- See which version you have:
cargo tree -i derive-com-impl(it also shows which of your dependencies pulls it in). - Update within your version requirement:
cargo update -p derive-com-impl. If the fix is a newer major or minor than your requirement allows, raise it in Cargo.toml (for examplederive-com-impl = "0.1.2") or update the dependency that pulls it in. - Check again with
cargo audit, or paste your Cargo.lock into our Cargo.toml checker.
Details from the advisory
Affected version of this crate, which is a required dependency in com-impl, provides a faulty implementation of the IUnknown::QueryInterface method.
QueryInterface implementation must call IUnknown::AddRef before returning the pointer, as describe in this documentation: <https://docs.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-queryinterface(refiid_void)>
As it is not incrementing the refcount as expected, the following calls to IUnknown::Release method will cause WMI to drop reference to the interface, and can lead to invalid reference.
This is documented in <https://docs.microsoft.com/en-us/windows/win32/learnwin32/managing-the-lifetime-of-an-object#reference-counting>
There is no simple workaround, as you can't know how many time QueryInterface will be called. The only way to quick fix this is to use the macro expanded version of the code and modify the QueryInterface method to add the AddRef call yourself.
The issue was corrected in commit 9803f31fbd1717d482d848f041044d061fca6da7.
References
- Package: crates.io/crates/derive-com-impl
- Advisory: rustsec.org/advisories/RUSTSEC-2021-0083.html
- Report: github.com/Connicpu/com-impl/issues/1
From the RustSec Advisory Database (CC0-1.0) via the OSV export, downloaded Oct 24, 2026. Severity score computed from the published CVSS vector.
Up next
Are you affected?Check your whole dependency treePaste Cargo.lock: every advisory, for your exact versions.Read it next →Also worth your time
Did this answer your question?