gnu: emacs-consult: Fix grammar.
[jackhill/guix/guix.git] / gnu / packages / patches / glib-CVE-2021-27219-02.patch
1 Backport of:
2
3 From be8834340a2d928ece82025463ae23dee2c333d0 Mon Sep 17 00:00:00 2001
4 From: Philip Withnall <pwithnall@endlessos.org>
5 Date: Thu, 4 Feb 2021 13:37:56 +0000
6 Subject: [PATCH 02/11] gio: Use g_memdup2() instead of g_memdup() in obvious
7 places
8 MIME-Version: 1.0
9 Content-Type: text/plain; charset=UTF-8
10 Content-Transfer-Encoding: 8bit
11
12 Convert all the call sites which use `g_memdup()`’s length argument
13 trivially (for example, by passing a `sizeof()`), so that they use
14 `g_memdup2()` instead.
15
16 In almost all of these cases the use of `g_memdup()` would not have
17 caused problems, but it will soon be deprecated, so best port away from
18 it.
19
20 Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
21 Helps: #2319
22 ---
23 gio/gdbusconnection.c | 5 +++--
24 gio/gdbusinterfaceskeleton.c | 3 ++-
25 gio/gfile.c | 7 ++++---
26 gio/gsettingsschema.c | 5 +++--
27 gio/gwin32registrykey.c | 8 +++++---
28 gio/tests/async-close-output-stream.c | 6 ++++--
29 gio/tests/gdbus-export.c | 5 +++--
30 gio/win32/gwinhttpfile.c | 9 +++++----
31 8 files changed, 29 insertions(+), 19 deletions(-)
32
33 diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
34 index f1f0921d4..d56453486 100644
35 --- a/gio/gdbusconnection.c
36 +++ b/gio/gdbusconnection.c
37 @@ -110,6 +110,7 @@
38 #include "gasyncinitable.h"
39 #include "giostream.h"
40 #include "gasyncresult.h"
41 +#include "gstrfuncsprivate.h"
42 #include "gtask.h"
43 #include "gmarshal-internal.h"
44
45 @@ -3997,7 +3998,7 @@ _g_dbus_interface_vtable_copy (const GDBusInterfaceVTable *vtable)
46 /* Don't waste memory by copying padding - remember to update this
47 * when changing struct _GDBusInterfaceVTable in gdbusconnection.h
48 */
49 - return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer));
50 + return g_memdup2 ((gconstpointer) vtable, 3 * sizeof (gpointer));
51 }
52
53 static void
54 @@ -4014,7 +4015,7 @@ _g_dbus_subtree_vtable_copy (const GDBusSubtreeVTable *vtable)
55 /* Don't waste memory by copying padding - remember to update this
56 * when changing struct _GDBusSubtreeVTable in gdbusconnection.h
57 */
58 - return g_memdup ((gconstpointer) vtable, 3 * sizeof (gpointer));
59 + return g_memdup2 ((gconstpointer) vtable, 3 * sizeof (gpointer));
60 }
61
62 static void
63 diff --git a/gio/gdbusinterfaceskeleton.c b/gio/gdbusinterfaceskeleton.c
64 index 4a06516c1..4a4b719a5 100644
65 --- a/gio/gdbusinterfaceskeleton.c
66 +++ b/gio/gdbusinterfaceskeleton.c
67 @@ -28,6 +28,7 @@
68 #include "gdbusmethodinvocation.h"
69 #include "gdbusconnection.h"
70 #include "gmarshal-internal.h"
71 +#include "gstrfuncsprivate.h"
72 #include "gtask.h"
73 #include "gioerror.h"
74
75 @@ -701,7 +702,7 @@ add_connection_locked (GDBusInterfaceSkeleton *interface_,
76 * properly before building the hooked_vtable, so we create it
77 * once at the last minute.
78 */
79 - interface_->priv->hooked_vtable = g_memdup (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable));
80 + interface_->priv->hooked_vtable = g_memdup2 (g_dbus_interface_skeleton_get_vtable (interface_), sizeof (GDBusInterfaceVTable));
81 interface_->priv->hooked_vtable->method_call = skeleton_intercept_handle_method_call;
82 }
83
84 diff --git a/gio/gfile.c b/gio/gfile.c
85 index ba93f7c75..88b341e7d 100644
86 --- a/gio/gfile.c
87 +++ b/gio/gfile.c
88 @@ -60,6 +60,7 @@
89 #include "gasyncresult.h"
90 #include "gioerror.h"
91 #include "glibintl.h"
92 +#include "gstrfuncsprivate.h"
93
94
95 /**
96 @@ -7884,7 +7885,7 @@ measure_disk_usage_progress (gboolean reporting,
97 g_main_context_invoke_full (g_task_get_context (task),
98 g_task_get_priority (task),
99 measure_disk_usage_invoke_progress,
100 - g_memdup (&progress, sizeof progress),
101 + g_memdup2 (&progress, sizeof progress),
102 g_free);
103 }
104
105 @@ -7902,7 +7903,7 @@ measure_disk_usage_thread (GTask *task,
106 data->progress_callback ? measure_disk_usage_progress : NULL, task,
107 &result.disk_usage, &result.num_dirs, &result.num_files,
108 &error))
109 - g_task_return_pointer (task, g_memdup (&result, sizeof result), g_free);
110 + g_task_return_pointer (task, g_memdup2 (&result, sizeof result), g_free);
111 else
112 g_task_return_error (task, error);
113 }
114 @@ -7926,7 +7927,7 @@ g_file_real_measure_disk_usage_async (GFile *file,
115
116 task = g_task_new (file, cancellable, callback, user_data);
117 g_task_set_source_tag (task, g_file_real_measure_disk_usage_async);
118 - g_task_set_task_data (task, g_memdup (&data, sizeof data), g_free);
119 + g_task_set_task_data (task, g_memdup2 (&data, sizeof data), g_free);
120 g_task_set_priority (task, io_priority);
121
122 g_task_run_in_thread (task, measure_disk_usage_thread);
123 diff --git a/gio/gsettingsschema.c b/gio/gsettingsschema.c
124 index 3a60b8c64..dded9b1ca 100644
125 --- a/gio/gsettingsschema.c
126 +++ b/gio/gsettingsschema.c
127 @@ -20,6 +20,7 @@
128
129 #include "gsettingsschema-internal.h"
130 #include "gsettings.h"
131 +#include "gstrfuncsprivate.h"
132
133 #include "gvdb/gvdb-reader.h"
134 #include "strinfo.c"
135 @@ -1058,9 +1059,9 @@ g_settings_schema_list_children (GSettingsSchema *schema)
136
137 if (g_str_has_suffix (key, "/"))
138 {
139 - gint length = strlen (key);
140 + gsize length = strlen (key);
141
142 - strv[j] = g_memdup (key, length);
143 + strv[j] = g_memdup2 (key, length);
144 strv[j][length - 1] = '\0';
145 j++;
146 }
147 diff --git a/gio/gwin32registrykey.c b/gio/gwin32registrykey.c
148 index c19fede4e..619fd48af 100644
149 --- a/gio/gwin32registrykey.c
150 +++ b/gio/gwin32registrykey.c
151 @@ -28,6 +28,8 @@
152 #include <ntstatus.h>
153 #include <winternl.h>
154
155 +#include "gstrfuncsprivate.h"
156 +
157 #ifndef _WDMDDK_
158 typedef enum _KEY_INFORMATION_CLASS {
159 KeyBasicInformation,
160 @@ -247,7 +249,7 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter)
161 new_iter->value_name_size = iter->value_name_size;
162
163 if (iter->value_data != NULL)
164 - new_iter->value_data = g_memdup (iter->value_data, iter->value_data_size);
165 + new_iter->value_data = g_memdup2 (iter->value_data, iter->value_data_size);
166
167 new_iter->value_data_size = iter->value_data_size;
168
169 @@ -268,8 +270,8 @@ g_win32_registry_value_iter_copy (const GWin32RegistryValueIter *iter)
170 new_iter->value_data_expanded_charsize = iter->value_data_expanded_charsize;
171
172 if (iter->value_data_expanded_u8 != NULL)
173 - new_iter->value_data_expanded_u8 = g_memdup (iter->value_data_expanded_u8,
174 - iter->value_data_expanded_charsize);
175 + new_iter->value_data_expanded_u8 = g_memdup2 (iter->value_data_expanded_u8,
176 + iter->value_data_expanded_charsize);
177
178 new_iter->value_data_expanded_u8_size = iter->value_data_expanded_charsize;
179
180 diff --git a/gio/tests/async-close-output-stream.c b/gio/tests/async-close-output-stream.c
181 index 5f6620275..d3f97a119 100644
182 --- a/gio/tests/async-close-output-stream.c
183 +++ b/gio/tests/async-close-output-stream.c
184 @@ -24,6 +24,8 @@
185 #include <stdlib.h>
186 #include <string.h>
187
188 +#include "gstrfuncsprivate.h"
189 +
190 #define DATA_TO_WRITE "Hello world\n"
191
192 typedef struct
193 @@ -147,9 +149,9 @@ prepare_data (SetupData *data,
194
195 data->expected_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->data_stream));
196
197 - g_assert_cmpint (data->expected_size, >, 0);
198 + g_assert_cmpuint (data->expected_size, >, 0);
199
200 - data->expected_output = g_memdup (written, (guint)data->expected_size);
201 + data->expected_output = g_memdup2 (written, data->expected_size);
202
203 /* then recreate the streams and prepare them for the asynchronous close */
204 destroy_streams (data);
205 diff --git a/gio/tests/gdbus-export.c b/gio/tests/gdbus-export.c
206 index 506c7458a..5513306f8 100644
207 --- a/gio/tests/gdbus-export.c
208 +++ b/gio/tests/gdbus-export.c
209 @@ -23,6 +23,7 @@
210 #include <string.h>
211
212 #include "gdbus-tests.h"
213 +#include "gstrfuncsprivate.h"
214
215 /* all tests rely on a shared mainloop */
216 static GMainLoop *loop = NULL;
217 @@ -671,7 +672,7 @@ subtree_introspect (GDBusConnection *connection,
218 g_assert_not_reached ();
219 }
220
221 - return g_memdup (interfaces, 2 * sizeof (void *));
222 + return g_memdup2 (interfaces, 2 * sizeof (void *));
223 }
224
225 static const GDBusInterfaceVTable *
226 @@ -727,7 +728,7 @@ dynamic_subtree_introspect (GDBusConnection *connection,
227 {
228 const GDBusInterfaceInfo *interfaces[2] = { &dyna_interface_info, NULL };
229
230 - return g_memdup (interfaces, 2 * sizeof (void *));
231 + return g_memdup2 (interfaces, 2 * sizeof (void *));
232 }
233
234 static const GDBusInterfaceVTable *
235 diff --git a/gio/win32/gwinhttpfile.c b/gio/win32/gwinhttpfile.c
236 index cf5eed31d..040ee8564 100644
237 --- a/gio/win32/gwinhttpfile.c
238 +++ b/gio/win32/gwinhttpfile.c
239 @@ -29,6 +29,7 @@
240 #include "gio/gfile.h"
241 #include "gio/gfileattribute.h"
242 #include "gio/gfileinfo.h"
243 +#include "gstrfuncsprivate.h"
244 #include "gwinhttpfile.h"
245 #include "gwinhttpfileinputstream.h"
246 #include "gwinhttpfileoutputstream.h"
247 @@ -393,10 +394,10 @@ g_winhttp_file_resolve_relative_path (GFile *file,
248 child = g_object_new (G_TYPE_WINHTTP_FILE, NULL);
249 child->vfs = winhttp_file->vfs;
250 child->url = winhttp_file->url;
251 - child->url.lpszScheme = g_memdup (winhttp_file->url.lpszScheme, (winhttp_file->url.dwSchemeLength+1)*2);
252 - child->url.lpszHostName = g_memdup (winhttp_file->url.lpszHostName, (winhttp_file->url.dwHostNameLength+1)*2);
253 - child->url.lpszUserName = g_memdup (winhttp_file->url.lpszUserName, (winhttp_file->url.dwUserNameLength+1)*2);
254 - child->url.lpszPassword = g_memdup (winhttp_file->url.lpszPassword, (winhttp_file->url.dwPasswordLength+1)*2);
255 + child->url.lpszScheme = g_memdup2 (winhttp_file->url.lpszScheme, (winhttp_file->url.dwSchemeLength+1)*2);
256 + child->url.lpszHostName = g_memdup2 (winhttp_file->url.lpszHostName, (winhttp_file->url.dwHostNameLength+1)*2);
257 + child->url.lpszUserName = g_memdup2 (winhttp_file->url.lpszUserName, (winhttp_file->url.dwUserNameLength+1)*2);
258 + child->url.lpszPassword = g_memdup2 (winhttp_file->url.lpszPassword, (winhttp_file->url.dwPasswordLength+1)*2);
259 child->url.lpszUrlPath = wnew_path;
260 child->url.dwUrlPathLength = wcslen (wnew_path);
261 child->url.lpszExtraInfo = NULL;
262 --
263 2.30.1
264