gnu: Add kafs-client
[jackhill/guix/guix.git] / gnu / packages / patches / glib-CVE-2021-27219-07.patch
1 Backport of:
2
3 From 2aaf593a9eb96d84fe3be740aca2810a97d95592 Mon Sep 17 00:00:00 2001
4 From: Philip Withnall <pwithnall@endlessos.org>
5 Date: Thu, 4 Feb 2021 13:50:37 +0000
6 Subject: [PATCH 07/11] gwin32: Use gsize internally in g_wcsdup()
7 MIME-Version: 1.0
8 Content-Type: text/plain; charset=UTF-8
9 Content-Transfer-Encoding: 8bit
10
11 This allows it to handle strings up to length `G_MAXSIZE` — previously
12 it would overflow with such strings.
13
14 Update the several copies of it identically.
15
16 Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
17 Helps: #2319
18 ---
19 gio/gwin32appinfo.c | 33 ++++++++++++++++++++++++++-------
20 gio/gwin32registrykey.c | 34 ++++++++++++++++++++++++++--------
21 2 files changed, 52 insertions(+), 15 deletions(-)
22
23 diff --git a/gio/gwin32appinfo.c b/gio/gwin32appinfo.c
24 index 9f335b370..dd7a96a4a 100644
25 --- a/gio/gwin32appinfo.c
26 +++ b/gio/gwin32appinfo.c
27 @@ -464,15 +464,34 @@ static GWin32RegistryKey *applications_key;
28 /* Watch this key */
29 static GWin32RegistryKey *classes_root_key;
30
31 +static gsize
32 +g_utf16_len (const gunichar2 *str)
33 +{
34 + gsize result;
35 +
36 + for (result = 0; str[0] != 0; str++, result++)
37 + ;
38 +
39 + return result;
40 +}
41 +
42 static gunichar2 *
43 -g_wcsdup (const gunichar2 *str, gssize str_size)
44 +g_wcsdup (const gunichar2 *str, gssize str_len)
45 {
46 - if (str_size == -1)
47 - {
48 - str_size = wcslen (str) + 1;
49 - str_size *= sizeof (gunichar2);
50 - }
51 - return g_memdup (str, str_size);
52 + gsize str_len_unsigned;
53 + gsize str_size;
54 +
55 + g_return_val_if_fail (str != NULL, NULL);
56 +
57 + if (str_len < 0)
58 + str_len_unsigned = g_utf16_len (str);
59 + else
60 + str_len_unsigned = (gsize) str_len;
61 +
62 + g_assert (str_len_unsigned <= G_MAXSIZE / sizeof (gunichar2) - 1);
63 + str_size = (str_len_unsigned + 1) * sizeof (gunichar2);
64 +
65 + return g_memdup2 (str, str_size);
66 }
67
68 #define URL_ASSOCIATIONS L"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\"
69 diff --git a/gio/gwin32registrykey.c b/gio/gwin32registrykey.c
70 index 619fd48af..fbd65311a 100644
71 --- a/gio/gwin32registrykey.c
72 +++ b/gio/gwin32registrykey.c
73 @@ -127,16 +127,34 @@ typedef enum
74 G_WIN32_REGISTRY_UPDATED_PATH = 1,
75 } GWin32RegistryKeyUpdateFlag;
76
77 +static gsize
78 +g_utf16_len (const gunichar2 *str)
79 +{
80 + gsize result;
81 +
82 + for (result = 0; str[0] != 0; str++, result++)
83 + ;
84 +
85 + return result;
86 +}
87 +
88 static gunichar2 *
89 -g_wcsdup (const gunichar2 *str,
90 - gssize str_size)
91 +g_wcsdup (const gunichar2 *str, gssize str_len)
92 {
93 - if (str_size == -1)
94 - {
95 - str_size = wcslen (str) + 1;
96 - str_size *= sizeof (gunichar2);
97 - }
98 - return g_memdup (str, str_size);
99 + gsize str_len_unsigned;
100 + gsize str_size;
101 +
102 + g_return_val_if_fail (str != NULL, NULL);
103 +
104 + if (str_len < 0)
105 + str_len_unsigned = g_utf16_len (str);
106 + else
107 + str_len_unsigned = (gsize) str_len;
108 +
109 + g_assert (str_len_unsigned <= G_MAXSIZE / sizeof (gunichar2) - 1);
110 + str_size = (str_len_unsigned + 1) * sizeof (gunichar2);
111 +
112 + return g_memdup2 (str, str_size);
113 }
114
115 /**
116 --
117 2.30.1
118