From ac8690e6f4ba4ac165d84d6f0f10b195a6c0a3dd Mon Sep 17 00:00:00 2001 From: dufresne_andy Date: Tue, 19 Dec 2023 10:49:51 +0800 Subject: [PATCH] Description:fix the problem that ubsan sub_overflow Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: dufresne_andy --- services/native/src/usb_right_db_helper.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/native/src/usb_right_db_helper.cpp b/services/native/src/usb_right_db_helper.cpp index 2e58aa89..a92e095a 100644 --- a/services/native/src/usb_right_db_helper.cpp +++ b/services/native/src/usb_right_db_helper.cpp @@ -404,12 +404,15 @@ int32_t UsbRightDbHelper::DeleteNormalExpiredRightRecord(int32_t uid, uint64_t e { std::lock_guard guard(databaseMutex_); std::string whereClause = {"uid = ? AND requestTime < ? AND validPeriod NOT IN (?, ?)"}; - std::vector whereArgs = {std::to_string(uid), std::to_string(expiredTime - USB_RIGHT_VALID_PERIOD_SET), + + uint64_t relativeExpiredTime = (expiredTime <= USB_RIGHT_VALID_PERIOD_SET) ? 0 : + (expiredTime - USB_RIGHT_VALID_PERIOD_SET); + std::vector whereArgs = {std::to_string(uid), std::to_string(relativeExpiredTime), std::to_string(USB_RIGHT_VALID_PERIOD_MIN), std::to_string(USB_RIGHT_VALID_PERIOD_MAX)}; int32_t ret = DeleteAndNoOtherOperation(whereClause, whereArgs); if (ret != USB_RIGHT_OK) { USB_HILOGE(MODULE_USB_SERVICE, - "failed: delete(uid=%{public}d, expr<%{public}" PRIu64 "): %{public}d", uid, expiredTime, ret); + "failed: delete(uid=%{public}d, expr<%{public}" PRIu64 "): %{public}d", uid, expiredTime, ret); } return ret; } -- Gitee