|
| 1 | +From f8cd5f93b2ba7fedf79fd4572ad3275bc8b52f77 Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 3 | +Date: Mon, 9 Jun 2025 07:06:12 -0400 |
| 4 | +Subject: [PATCH] Address CVE-2025-4373 |
| 5 | +Upstream Patch Reference: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4588.patch |
| 6 | + |
| 7 | +--- |
| 8 | + glib/gstring.c | 36 +++++++++++++++++++++++------------- |
| 9 | + 1 file changed, 23 insertions(+), 13 deletions(-) |
| 10 | + |
| 11 | +diff --git a/glib/gstring.c b/glib/gstring.c |
| 12 | +index 9f04144..d016b65 100644 |
| 13 | +--- a/glib/gstring.c |
| 14 | ++++ b/glib/gstring.c |
| 15 | +@@ -490,8 +490,9 @@ g_string_insert_len (GString *string, |
| 16 | + return string; |
| 17 | + |
| 18 | + if (len < 0) |
| 19 | +- len = strlen (val); |
| 20 | +- len_unsigned = len; |
| 21 | ++ len_unsigned = strlen (val); |
| 22 | ++ else |
| 23 | ++ len_unsigned = len; |
| 24 | + |
| 25 | + if (pos < 0) |
| 26 | + pos_unsigned = string->len; |
| 27 | +@@ -788,10 +789,12 @@ g_string_insert_c (GString *string, |
| 28 | + g_string_maybe_expand (string, 1); |
| 29 | + |
| 30 | + if (pos < 0) |
| 31 | +- pos = string->len; |
| 32 | ++ pos_unsigned = string->len; |
| 33 | + else |
| 34 | +- g_return_val_if_fail ((gsize) pos <= string->len, string); |
| 35 | +- pos_unsigned = pos; |
| 36 | ++ { |
| 37 | ++ pos_unsigned = pos; |
| 38 | ++ g_return_val_if_fail (pos_unsigned <= string->len, string); |
| 39 | ++ } |
| 40 | + |
| 41 | + /* If not just an append, move the old stuff */ |
| 42 | + if (pos_unsigned < string->len) |
| 43 | +@@ -824,6 +827,7 @@ g_string_insert_unichar (GString *string, |
| 44 | + gssize pos, |
| 45 | + gunichar wc) |
| 46 | + { |
| 47 | ++ gsize pos_unsigned; |
| 48 | + gint charlen, first, i; |
| 49 | + gchar *dest; |
| 50 | + |
| 51 | +@@ -865,15 +869,18 @@ g_string_insert_unichar (GString *string, |
| 52 | + g_string_maybe_expand (string, charlen); |
| 53 | + |
| 54 | + if (pos < 0) |
| 55 | +- pos = string->len; |
| 56 | ++ pos_unsigned = string->len; |
| 57 | + else |
| 58 | +- g_return_val_if_fail ((gsize) pos <= string->len, string); |
| 59 | ++ { |
| 60 | ++ pos_unsigned = pos; |
| 61 | ++ g_return_val_if_fail (pos_unsigned <= string->len, string); |
| 62 | ++ } |
| 63 | + |
| 64 | + /* If not just an append, move the old stuff */ |
| 65 | +- if ((gsize) pos < string->len) |
| 66 | +- memmove (string->str + pos + charlen, string->str + pos, string->len - pos); |
| 67 | ++ if (pos_unsigned < string->len) |
| 68 | ++ memmove (string->str + pos_unsigned + charlen, string->str + pos_unsigned, string->len - pos_unsigned); |
| 69 | + |
| 70 | +- dest = string->str + pos; |
| 71 | ++ dest = string->str + pos_unsigned; |
| 72 | + /* Code copied from g_unichar_to_utf() */ |
| 73 | + for (i = charlen - 1; i > 0; --i) |
| 74 | + { |
| 75 | +@@ -931,6 +938,7 @@ g_string_overwrite_len (GString *string, |
| 76 | + const gchar *val, |
| 77 | + gssize len) |
| 78 | + { |
| 79 | ++ gssize len_unsigned; |
| 80 | + gsize end; |
| 81 | + |
| 82 | + g_return_val_if_fail (string != NULL, NULL); |
| 83 | +@@ -942,14 +950,16 @@ g_string_overwrite_len (GString *string, |
| 84 | + g_return_val_if_fail (pos <= string->len, string); |
| 85 | + |
| 86 | + if (len < 0) |
| 87 | +- len = strlen (val); |
| 88 | ++ len_unsigned = strlen (val); |
| 89 | ++ else |
| 90 | ++ len_unsigned = len; |
| 91 | + |
| 92 | +- end = pos + len; |
| 93 | ++ end = pos + len_unsigned; |
| 94 | + |
| 95 | + if (end > string->len) |
| 96 | + g_string_maybe_expand (string, end - string->len); |
| 97 | + |
| 98 | +- memcpy (string->str + pos, val, len); |
| 99 | ++ memcpy (string->str + pos, val, len_unsigned); |
| 100 | + |
| 101 | + if (end > string->len) |
| 102 | + { |
| 103 | +-- |
| 104 | +2.34.1 |
| 105 | + |
0 commit comments