Resolves: RHEL-108555,RHEL-108568,RHEL-108576,RHEL-108584,RHEL-108596,RHEL-108598,RHEL-109096,RHEL-109488,RHEL-111065,RHEL-31756,RHEL-50103
48 lines
1.4 KiB
Diff
48 lines
1.4 KiB
Diff
From 9f7d490b1c16f0444987dab7ce70287b59d98cf9 Mon Sep 17 00:00:00 2001
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
Date: Tue, 14 Feb 2023 04:27:27 +0900
|
|
Subject: [PATCH] time-util: use usec_add() and usec_sub_unsigned()
|
|
|
|
And move the check with USEC_TIMESTAMP_FORMATTABLE_MAX at the end,
|
|
as usec_add() can handle overflow correctly.
|
|
|
|
(cherry picked from commit db43717e982e1361eee4bdcd92167d6c47eb627c)
|
|
|
|
Related: RHEL-109488
|
|
---
|
|
src/basic/time-util.c | 17 +++++++----------
|
|
1 file changed, 7 insertions(+), 10 deletions(-)
|
|
|
|
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
|
|
index 047dad0fec..ba5e17bd9d 100644
|
|
--- a/src/basic/time-util.c
|
|
+++ b/src/basic/time-util.c
|
|
@@ -881,20 +881,17 @@ from_tm:
|
|
if (x < 0)
|
|
return -EINVAL;
|
|
|
|
- usec = (usec_t) x * USEC_PER_SEC + x_usec;
|
|
- if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
|
- return -EINVAL;
|
|
+ usec = usec_add(x * USEC_PER_SEC, x_usec);
|
|
|
|
finish:
|
|
- if (usec + plus < usec) /* overflow? */
|
|
- return -EINVAL;
|
|
- usec += plus;
|
|
- if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
|
+ usec = usec_add(usec, plus);
|
|
+
|
|
+ if (usec < minus)
|
|
return -EINVAL;
|
|
|
|
- if (usec >= minus)
|
|
- usec -= minus;
|
|
- else
|
|
+ usec = usec_sub_unsigned(usec, minus);
|
|
+
|
|
+ if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
|
return -EINVAL;
|
|
|
|
if (ret)
|