public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libuuid: Fix pre-1970 UUID v1 timestamp wraparound
@ 2025-12-13 20:04 Kiran Rangoon
  2025-12-13 23:36 ` Thomas Weißschuh 
  2025-12-14  1:01 ` [PATCH v2] " Kiran Rangoon
  0 siblings, 2 replies; 19+ messages in thread
From: Kiran Rangoon @ 2025-12-13 20:04 UTC (permalink / raw)
  To: util-linux; +Cc: Kiran Rangoon

gregorian_to_unix now returns -1 and sets errno=EOVERFLOW
for timestamps before the Unix epoch. uuid_time_v1 and uuid_time_v6
now use signed arithmetic to prevent unsigned wraparound.

This fixes uuidparse displaying far-future dates for historical UUIDs.

Signed-off-by: Kiran Rangoon <kiranrangoon0@gmail.com>
---
 libuuid/src/uuid_time.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/libuuid/src/uuid_time.c b/libuuid/src/uuid_time.c
index c7516152b..b7fcc892d 100644
--- a/libuuid/src/uuid_time.c
+++ b/libuuid/src/uuid_time.c
@@ -60,15 +60,22 @@
 /* prototype to make compiler happy */
 time_t __uuid_time(const uuid_t uu, struct timeval *ret_tv);
 
-static uint64_t gregorian_to_unix(uint64_t ts)
+static int64_t gregorian_to_unix(uint64_t ts)
 {
-	return ts - ((((uint64_t) 0x01B21DD2) << 32) + 0x13814000);
+    uint64_t offset = ((((uint64_t) 0x01B21DD2) << 32) + 0x13814000);
+
+    if (ts < offset) {
+        errno = EOVERFLOW;
+        return -1;
+    }
+
+    return ts - offset;
 }
 
 static void uuid_time_v1(const struct uuid *uuid, struct timeval *tv)
 {
 	uint32_t high;
-	uint64_t clock_reg;
+	int64_t clock_reg;
 
 	high = uuid->time_mid | ((uuid->time_hi_and_version & 0xFFF) << 16);
 	clock_reg = uuid->time_low | ((uint64_t) high << 32);
@@ -80,7 +87,7 @@ static void uuid_time_v1(const struct uuid *uuid, struct timeval *tv)
 
 static void uuid_time_v6(const struct uuid *uuid, struct timeval *tv)
 {
-	uint64_t clock_reg;
+	int64_t clock_reg;
 
 	clock_reg = uuid->time_low;
 	clock_reg <<= 16;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2025-12-28  8:47 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-13 20:04 [PATCH] libuuid: Fix pre-1970 UUID v1 timestamp wraparound Kiran Rangoon
2025-12-13 23:36 ` Thomas Weißschuh 
2025-12-14  1:01 ` [PATCH v2] " Kiran Rangoon
2025-12-16 13:08   ` Thomas Weißschuh
2025-12-16 20:40     ` Kiran
2025-12-16 23:21       ` Thomas Weißschuh
2025-12-17 20:42         ` [PATCH v3 1/2] libuuid: Refactor UUID time conversion for pre-epoch dates Kiran Rangoon
2025-12-17 20:59         ` Kiran Rangoon
2025-12-18 21:31         ` Kiran Rangoon
2025-12-19 11:40           ` Thomas Weißschuh
2025-12-23 18:00             ` [PATCH v4 0/4] libuuid: Fix pre-1970 UUID timestamp overflow Kiran Rangoon
2025-12-23 18:00               ` [PATCH v4 1/4] libuuid: simplify gregorian-to-unix offset calculation Kiran Rangoon
2025-12-23 18:00               ` [PATCH v4 2/4] libuuid: refactor gregorian_to_unix to populate timeval directly Kiran Rangoon
2025-12-23 18:03               ` [PATCH v4 1/4] libuuid: simplify gregorian-to-unix offset calculation Kiran Rangoon
2025-12-23 18:22               ` [PATCH v4 0/4] libuuid: Fix pre-1970 UUID timestamp overflow Thomas Weißschuh 
2025-12-28  8:47               ` Thomas Weißschuh
2025-12-23 18:04             ` [PATCH v4 3/4] libuuid: fix timestamp overflow for pre-1970 dates Kiran Rangoon
2025-12-23 18:05             ` [PATCH v4 4/4] tests: correct UUID timestamp test expectations Kiran Rangoon
2025-12-17 11:01   ` [PATCH v2] libuuid: Fix pre-1970 UUID v1 timestamp wraparound Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox