diff options
author | Mike McTernan <mikemcternan@google.com> | 2023-05-15 18:22:51 +0100 |
---|---|---|
committer | Mike McTernan <mikemcternan@google.com> | 2023-05-15 18:22:51 +0100 |
commit | d2bedb3307df699b5764dffee3c7d447e0f4dc7a (patch) | |
tree | 7866cd5f02d5903f0aae264866da6a7756a86c79 | |
parent | f2b6bf540cf3ec6611e71331ef1b78029564859c (diff) | |
download | confirmationui-d2bedb3307df699b5764dffee3c7d447e0f4dc7a.tar.gz |
trusty: tui: Fix memory leak on failure path
Bug: 272813227
Test: run fuzzer
Change-Id: Ifc86f2f5e210a7c1fb0b0564f1da00afab333c35
-rw-r--r-- | src/main.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp index f333907..f098aef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,7 @@ static inline bool is_inited(struct chan_ctx* ctx) { static bool get_auth_token_key(teeui::AuthTokenKey& authKey) { long rc = keymaster_open(); + bool result = false; if (rc < 0) { return false; @@ -52,17 +53,18 @@ static bool get_auth_token_key(teeui::AuthTokenKey& authKey) { uint32_t local_length = 0; rc = keymaster_get_auth_token_key(session, &key, &local_length); keymaster_close(session); - TLOGD("%s, key length = %u\n", __func__, local_length); - if (local_length != teeui::kAuthTokenKeySize) { - return false; - } + if (rc == NO_ERROR) { - memcpy(authKey.data(), key, teeui::kAuthTokenKeySize); - } else { - return false; + if (local_length == teeui::kAuthTokenKeySize) { + /* Success - store the key */ + memcpy(authKey.data(), key, teeui::kAuthTokenKeySize); + result = true; + } + + free(key); } - return true; + return result; } struct __attribute__((__packed__)) confirmationui_req { |