|
| 1 | +From dfc124ea7797cead9b9a21b7d325daf0028a245d Mon Sep 17 00:00:00 2001 |
| 2 | +From: Alexander Kanavin < [email protected]> |
| 3 | +Date: Tue, 22 Aug 2023 19:57:48 +0200 |
| 4 | +Subject: [PATCH 1/2] glib/gfileutils.c: use 64 bits for value in |
| 5 | + get_tmp_file() |
| 6 | + |
| 7 | +On 32 bit systems 'long' value will overflow in 2038 and become negative. |
| 8 | +As it is used to index into letters array, and % operation preserves signs, |
| 9 | +data corruption will then occur. |
| 10 | + |
| 11 | +Signed-off-by: Alexander Kanavin < [email protected]> |
| 12 | +--- |
| 13 | + glib/gfileutils.c | 4 ++-- |
| 14 | + 1 file changed, 2 insertions(+), 2 deletions(-) |
| 15 | + |
| 16 | +diff --git a/glib/gfileutils.c b/glib/gfileutils.c |
| 17 | +index fd5cd3b..645c277 100644 |
| 18 | +--- a/glib/gfileutils.c |
| 19 | ++++ b/glib/gfileutils.c |
| 20 | +@@ -1497,7 +1497,7 @@ get_tmp_file (gchar *tmpl, |
| 21 | + static const char letters[] = |
| 22 | + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
| 23 | + static const int NLETTERS = sizeof (letters) - 1; |
| 24 | +- glong value; |
| 25 | ++ gint64 value; |
| 26 | + gint64 now_us; |
| 27 | + static int counter = 0; |
| 28 | + |
| 29 | +@@ -1518,7 +1518,7 @@ get_tmp_file (gchar *tmpl, |
| 30 | + |
| 31 | + for (count = 0; count < 100; value += 7777, ++count) |
| 32 | + { |
| 33 | +- glong v = value; |
| 34 | ++ gint64 v = value; |
| 35 | + |
| 36 | + /* Fill in the random bits. */ |
| 37 | + XXXXXX[0] = letters[v % NLETTERS]; |
| 38 | +-- |
| 39 | +2.45.4 |
| 40 | + |
| 41 | + |
| 42 | +From 806d8dd3dd9cc96192258723eb356d9ebd1d1876 Mon Sep 17 00:00:00 2001 |
| 43 | +From: Michael Catanzaro < [email protected]> |
| 44 | +Date: Tue, 1 Jul 2025 10:58:07 -0500 |
| 45 | +Subject: [PATCH 2/2] gfileutils: fix computation of temporary file name |
| 46 | + |
| 47 | +We need to ensure that the value we use to index into the letters array |
| 48 | +is always positive. |
| 49 | + |
| 50 | +Fixes #3716 |
| 51 | + |
| 52 | +Signed-off-by: Azure Linux Security Servicing Account < [email protected]> |
| 53 | +Upstream-reference: https://gitlab.gnome.org/GNOME/glib/-/commit/285db475ecaa4d2cc39ce326b4c63aacb87ca6ad.patch https://gitlab.gnome.org/GNOME/glib/-/commit/61e963284889ddb4544e6f1d5261c16120f6fcc3.patch |
| 54 | +--- |
| 55 | + glib/gfileutils.c | 8 ++++---- |
| 56 | + 1 file changed, 4 insertions(+), 4 deletions(-) |
| 57 | + |
| 58 | +diff --git a/glib/gfileutils.c b/glib/gfileutils.c |
| 59 | +index 645c277..a9cf9f7 100644 |
| 60 | +--- a/glib/gfileutils.c |
| 61 | ++++ b/glib/gfileutils.c |
| 62 | +@@ -1497,9 +1497,9 @@ get_tmp_file (gchar *tmpl, |
| 63 | + static const char letters[] = |
| 64 | + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
| 65 | + static const int NLETTERS = sizeof (letters) - 1; |
| 66 | +- gint64 value; |
| 67 | +- gint64 now_us; |
| 68 | +- static int counter = 0; |
| 69 | ++ guint64 value; |
| 70 | ++ guint64 now_us; |
| 71 | ++ static guint counter = 0; |
| 72 | + |
| 73 | + g_return_val_if_fail (tmpl != NULL, -1); |
| 74 | + |
| 75 | +@@ -1518,7 +1518,7 @@ get_tmp_file (gchar *tmpl, |
| 76 | + |
| 77 | + for (count = 0; count < 100; value += 7777, ++count) |
| 78 | + { |
| 79 | +- gint64 v = value; |
| 80 | ++ guint64 v = value; |
| 81 | + |
| 82 | + /* Fill in the random bits. */ |
| 83 | + XXXXXX[0] = letters[v % NLETTERS]; |
| 84 | +-- |
| 85 | +2.45.4 |
| 86 | + |
0 commit comments