Skip to content

Commit cd04a4d

Browse files
authored
Ensure wrapped key is freed in get_aes256_key (#6997)
1 parent d4d571d commit cd04a4d

File tree

1 file changed

+8
-0
lines changed
  • components/support/rc_crypto/nss/src/pk11

1 file changed

+8
-0
lines changed

components/support/rc_crypto/nss/src/pk11/sym_key.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ fn get_aes256_key(name: &str) -> Result<SymKey> {
217217
}
218218
.map_err(|_| get_last_error())?;
219219

220+
// This cleanup will not run if a previous operation fails and causes an early return.
221+
// Using an RAII-style wrapper would be preferable to ensure the item is always freed,
222+
// but given that an earlier failure likely prevents startup, it is acceptable.
223+
//
224+
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1992756 for a follow-up
225+
// improvement.
226+
unsafe { nss_sys::SECITEM_FreeItem(wrapped_key, nss_sys::PR_TRUE) }
227+
220228
map_nss_secstatus(|| unsafe { nss_sys::PK11_ExtractKeyValue(sym_key.as_mut_ptr()) })?;
221229
Ok(sym_key)
222230
}

0 commit comments

Comments
 (0)