Skip to content

Commit

Permalink
Fix start_auth_session resource leak
Browse files Browse the repository at this point in the history
  • Loading branch information
duanying committed Jun 5, 2024
1 parent e06704c commit f5d9f85
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
30 changes: 20 additions & 10 deletions tss-esapi/src/abstraction/ak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,16 @@ pub fn load_ak(
.with_decrypt(true)
.with_encrypt(true)
.build();
context.tr_sess_set_attributes(
policy_auth_session,
session_attributes,
session_attributes_mask,
)?;
context
.tr_sess_set_attributes(
policy_auth_session,
session_attributes,
session_attributes_mask,
)
.or_else(|e| {
ctx.flush_context(SessionHandle::from(policy_auth_session).into())?;
Err(e)
})?;

let key_handle = context.execute_with_temporary_object(
SessionHandle::from(policy_auth_session).into(),
Expand Down Expand Up @@ -182,11 +187,16 @@ pub fn create_ak<IKC: IntoKeyCustomization>(
.with_decrypt(true)
.with_encrypt(true)
.build();
context.tr_sess_set_attributes(
policy_auth_session,
session_attributes,
session_attributes_mask,
)?;
context
.tr_sess_set_attributes(
policy_auth_session,
session_attributes,
session_attributes_mask,
)
.or_else(|e| {
ctx.flush_context(SessionHandle::from(policy_auth_session).into())?;
Err(e)
})?;

context.execute_with_temporary_object(
SessionHandle::from(policy_auth_session).into(),
Expand Down
6 changes: 5 additions & 1 deletion tss-esapi/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ impl Context {
.with_decrypt(true)
.with_encrypt(true)
.build();
self.tr_sess_set_attributes(auth_session, session_attributes, session_attributes_mask)?;
self.tr_sess_set_attributes(auth_session, session_attributes, session_attributes_mask)
.or_else(|e| {
ctx.flush_context(SessionHandle::from(auth_session).into())?;
Err(e)
})?;

let res = self.execute_with_session(Some(auth_session), f);

Expand Down

0 comments on commit f5d9f85

Please sign in to comment.