diff options
author | Ira Lytvynenko <ILytvynenko@luxoft.com> | 2017-04-12 20:33:44 +0300 |
---|---|---|
committer | Ira Lytvynenko <ILytvynenko@luxoft.com> | 2017-05-11 12:51:16 +0300 |
commit | ffa1498f4c2eb414232efa2d7b6d7297de650f90 (patch) | |
tree | e356b896a015b47e98c350c360885e9673e89c95 | |
parent | 9e7a39af22c3587580cb2dcff44e6a9b6956d02c (diff) | |
download | sdl_core-ffa1498f4c2eb414232efa2d7b6d7297de650f90.tar.gz |
Fix UPDATE_NEEDED is sent in case of unconsented device
Add check that pt_exchanged_x_days_after_epoch is initialized
-rw-r--r-- | src/components/policy/policy_external/src/cache_manager.cc | 14 | ||||
-rw-r--r-- | src/components/policy/policy_regular/src/cache_manager.cc | 14 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index 85c9519a06..7eb74c2a53 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -1035,16 +1035,22 @@ bool CacheManager::SetCountersPassedForSuccessfulUpdate( int CacheManager::DaysBeforeExchange(uint16_t current) { LOG4CXX_AUTO_TRACE(logger_); CACHE_MANAGER_CHECK(0); + + const rpc::Optional<rpc::Integer<uint16_t, 0, 65535> >& days_after_epoch = + (pt_->policy_table.module_meta->pt_exchanged_x_days_after_epoch); + + if (!days_after_epoch->is_initialized()) { + return -1; + } + const uint8_t limit = pt_->policy_table.module_config.exchange_after_x_days; LOG4CXX_DEBUG(logger_, "Exchange after: " << static_cast<int>(limit) << " days"); - const uint16_t days_after_epoch = - (*pt_->policy_table.module_meta->pt_exchanged_x_days_after_epoch); - LOG4CXX_DEBUG(logger_, "Epoch since last update: " << days_after_epoch); + LOG4CXX_DEBUG(logger_, "Epoch since last update: " << *days_after_epoch); const uint16_t actual = - std::max(static_cast<uint16_t>(current - days_after_epoch), uint16_t(0)); + std::max(static_cast<uint16_t>(current - *days_after_epoch), uint16_t(0)); LOG4CXX_DEBUG(logger_, "The days since last update: " << actual); return std::max(limit - actual, 0); diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index acdece0a70..e1a6544c23 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -539,16 +539,22 @@ bool CacheManager::SetCountersPassedForSuccessfulUpdate( int CacheManager::DaysBeforeExchange(int current) { LOG4CXX_AUTO_TRACE(logger_); CACHE_MANAGER_CHECK(0); + + const rpc::Optional<rpc::Integer<uint16_t, 0, 65535> >& days_after_epoch = + (pt_->policy_table.module_meta->pt_exchanged_x_days_after_epoch); + + if (!days_after_epoch->is_initialized()) { + return -1; + } + const uint8_t limit = pt_->policy_table.module_config.exchange_after_x_days; LOG4CXX_DEBUG(logger_, "Exchange after: " << static_cast<int>(limit) << " days"); - const uint16_t days_after_epoch = - (*pt_->policy_table.module_meta->pt_exchanged_x_days_after_epoch); - LOG4CXX_DEBUG(logger_, "Epoch since last update: " << days_after_epoch); + LOG4CXX_DEBUG(logger_, "Epoch since last update: " << *days_after_epoch); const uint16_t actual = - std::max(static_cast<uint16_t>(current - days_after_epoch), uint16_t(0)); + std::max(static_cast<uint16_t>(current - *days_after_epoch), uint16_t(0)); LOG4CXX_DEBUG(logger_, "The days since last update: " << actual); return std::max(limit - actual, 0); |