diff options
author | Liening.Liu <Liening.Liu@unisoc.com> | 2023-04-28 16:27:20 +0800 |
---|---|---|
committer | David Zeuthen <zeuthen@google.com> | 2023-05-01 16:05:06 +0000 |
commit | 50a5f15f5fb4b7aea96172851f3bff89b99d70ae (patch) | |
tree | dae27172d03ff0737f72e3e717012780b4ec8a3f /identity/CredentialData.cpp | |
parent | f20c0ddd095013f983d0f73aee0285331bfae4e3 (diff) | |
download | security-50a5f15f5fb4b7aea96172851f3bff89b99d70ae.tar.gz |
Fix the overflow when converting current time to milliseconds on 32bit system
Test: Vts/Cts
Bug: 279998685
Change-Id: If8df10e7bb04527e1d9d18f03439bae4ca8dc8fa
Diffstat (limited to 'identity/CredentialData.cpp')
-rw-r--r-- | identity/CredentialData.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/identity/CredentialData.cpp b/identity/CredentialData.cpp index 1bf1527b..803e6715 100644 --- a/identity/CredentialData.cpp +++ b/identity/CredentialData.cpp @@ -520,8 +520,12 @@ AuthKeyData* CredentialData::findAuthKey_(bool allowUsingExhaustedKeys, bool allowUsingExpiredKeys) { AuthKeyData* candidate = nullptr; - int64_t nowMilliSeconds = - std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()) * 1000; + time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + int64_t nowMilliSeconds; + if (__builtin_mul_overflow(int64_t(now), int64_t(1000), &nowMilliSeconds)) { + LOG(ERROR) << "Overflow converting " << now << " to milliseconds"; + return nullptr; + } int n = 0; for (AuthKeyData& data : authKeyDatas_) { |