Package: gtk+2.0 / 2.24.32-3

Consistently-use-g_stat-and-GStatBuf.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
From: Eduard Braun <eduard.braun2@gmx.de>
Date: Sat, 13 Jan 2018 23:09:51 +0100
Subject: Consistently use g_stat and GStatBuf

Replace "stat struct" with "GStatBuf" and "stat" with "g_stat" where
appropriate to fix cross-platform issues, specifically on Windows.

Code should be identical on *nix but fixes some serious issues
on Windows:
- Field widths of "struct stat" are not constant on Windows.
  If the stat function does not match the stat struct used
  it will cause overwrites and undefined behavior
- The Windows stat function needs a properly encoded filename.
  In many places we pass an UTF-8 encoded value which breaks as soon
  as non-ASCII characters are involved.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=787772
Origin: upstream, 2.24.33, commit:eec3ce0b4eb25cf290ff649d3d87f7f0b25c02e4
---
 demos/pixbuf-init.c     |  8 +++-----
 gtk/gtkfilesel.c        | 30 +++++++++++++++---------------
 gtk/gtkiconcache.c      |  4 ++--
 gtk/gtkicontheme.c      |  6 +++---
 gtk/gtkrc.c             |  4 ++--
 gtk/gtkrecentmanager.c  |  4 ++--
 gtk/tests/pixbuf-init.c |  8 +++-----
 gtk/updateiconcache.c   |  4 ++--
 tests/testfilechooser.c | 10 +++++-----
 tests/testgtk.c         |  6 +++---
 tests/testtext.c        |  6 +++---
 11 files changed, 43 insertions(+), 47 deletions(-)

diff --git a/demos/pixbuf-init.c b/demos/pixbuf-init.c
index 898de45..20e35e5 100644
--- a/demos/pixbuf-init.c
+++ b/demos/pixbuf-init.c
@@ -1,15 +1,13 @@
 #include "config.h"
 #include <glib.h>
-
-#include <sys/stat.h>
-#include <stdlib.h>
+#include <glib/gstdio.h>
 
 static gboolean
 file_exists (const char *filename)
 {
-  struct stat statbuf;
+  GStatBuf statbuf;
 
-  return stat (filename, &statbuf) == 0;
+  return g_stat (filename, &statbuf) == 0;
 }
 
 void
diff --git a/gtk/gtkfilesel.c b/gtk/gtkfilesel.c
index d18c307..245bdf1 100644
--- a/gtk/gtkfilesel.c
+++ b/gtk/gtkfilesel.c
@@ -325,7 +325,7 @@ static CompletionDir* open_ref_dir         (gchar* text_to_complete,
 					    CompletionState* cmpl_state);
 #ifndef G_PLATFORM_WIN32
 static gboolean       check_dir            (gchar *dir_name, 
-					    struct stat *result, 
+					    GStatBuf *result, 
 					    gboolean *stat_subdirs);
 #endif
 static CompletionDir* open_dir             (gchar* dir_name,
@@ -337,11 +337,11 @@ static CompletionDir* open_user_dir        (const gchar* text_to_complete,
 static CompletionDir* open_relative_dir    (gchar* dir_name, CompletionDir* dir,
 					    CompletionState *cmpl_state);
 static CompletionDirSent* open_new_dir     (gchar* dir_name, 
-					    struct stat* sbuf,
+					    GStatBuf *sbuf,
 					    gboolean stat_subdirs);
 static gint           correct_dir_fullname (CompletionDir* cmpl_dir);
 static gint           correct_parent       (CompletionDir* cmpl_dir,
-					    struct stat *sbuf);
+					    GStatBuf *sbuf);
 #ifndef G_PLATFORM_WIN32
 static gchar*         find_parent_dir_fullname    (gchar* dirname);
 #endif
@@ -2984,9 +2984,9 @@ open_relative_dir (gchar           *dir_name,
 
 /* after the cache lookup fails, really open a new directory */
 static CompletionDirSent*
-open_new_dir (gchar       *dir_name,
-	      struct stat *sbuf,
-	      gboolean     stat_subdirs)
+open_new_dir (gchar    *dir_name,
+	      GStatBuf *sbuf,
+	      gboolean  stat_subdirs)
 {
   CompletionDirSent *sent;
   GDir *directory;
@@ -2995,7 +2995,7 @@ open_new_dir (gchar       *dir_name,
   gint entry_count = 0;
   gint n_entries = 0;
   gint i;
-  struct stat ent_sbuf;
+  GStatBuf ent_sbuf;
   GString *path;
   gchar *sys_dir_name;
 
@@ -3101,9 +3101,9 @@ open_new_dir (gchar       *dir_name,
 #ifndef G_PLATFORM_WIN32
 
 static gboolean
-check_dir (gchar       *dir_name,
-	   struct stat *result,
-	   gboolean    *stat_subdirs)
+check_dir (gchar    *dir_name,
+	   GStatBuf *result,
+	   gboolean *stat_subdirs)
 {
   /* A list of directories that we know only contain other directories.
    * Trying to stat every file in these directories would be very
@@ -3113,7 +3113,7 @@ check_dir (gchar       *dir_name,
   static struct {
     const gchar name[5];
     gboolean present;
-    struct stat statbuf;
+    GStatBuf statbuf;
   } no_stat_dirs[] = {
     { "/afs", FALSE, { 0 } },
     { "/net", FALSE, { 0 } }
@@ -3172,7 +3172,7 @@ open_dir (gchar           *dir_name,
 	  CompletionState *cmpl_state)
 {
 #ifndef G_PLATFORM_WIN32
-  struct stat sbuf;
+  GStatBuf sbuf;
   gboolean stat_subdirs;
   GList* cdsl;
 #endif
@@ -3238,7 +3238,7 @@ correct_dir_fullname (CompletionDir* cmpl_dir)
   gint length = strlen (cmpl_dir->fullname);
   gchar *first_slash = strchr (cmpl_dir->fullname, G_DIR_SEPARATOR);
   gchar *sys_filename;
-  struct stat sbuf;
+  GStatBuf sbuf;
 
   /* Does it end with /. (\.) ? */
   if (length >= 2 &&
@@ -3338,9 +3338,9 @@ correct_dir_fullname (CompletionDir* cmpl_dir)
 
 static gint
 correct_parent (CompletionDir *cmpl_dir,
-		struct stat   *sbuf)
+		GStatBuf      *sbuf)
 {
-  struct stat parbuf;
+  GStatBuf parbuf;
   gchar *last_slash;
   gchar *first_slash;
 #ifndef G_PLATFORM_WIN32
diff --git a/gtk/gtkiconcache.c b/gtk/gtkiconcache.c
index 576dd94..143f8f1 100644
--- a/gtk/gtkiconcache.c
+++ b/gtk/gtkiconcache.c
@@ -92,8 +92,8 @@ _gtk_icon_cache_new_for_path (const gchar *path)
 
   gchar *cache_filename;
   gint fd = -1;
-  struct stat st;
-  struct stat path_st;
+  GStatBuf st;
+  GStatBuf path_st;
   CacheInfo info;
 
    /* Check if we have a cache file */
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 470158c..60661c8 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -902,7 +902,7 @@ insert_theme (GtkIconTheme *icon_theme, const char *theme_name)
   GKeyFile *theme_file;
   GError *error = NULL;
   IconThemeDirMtime *dir_mtime;
-  struct stat stat_buf;
+  GStatBuf stat_buf;
   
   priv = icon_theme->priv;
 
@@ -1052,7 +1052,7 @@ load_themes (GtkIconTheme *icon_theme)
   IconSuffix old_suffix, new_suffix;
   GTimeVal tv;
   IconThemeDirMtime *dir_mtime;
-  struct stat stat_buf;
+  GStatBuf stat_buf;
   
   priv = icon_theme->priv;
 
@@ -1898,7 +1898,7 @@ rescan_themes (GtkIconTheme *icon_theme)
   IconThemeDirMtime *dir_mtime;
   GList *d;
   int stat_res;
-  struct stat stat_buf;
+  GStatBuf stat_buf;
   GTimeVal tv;
 
   priv = icon_theme->priv;
diff --git a/gtk/gtkrc.c b/gtk/gtkrc.c
index 50b2563..952010e 100644
--- a/gtk/gtkrc.c
+++ b/gtk/gtkrc.c
@@ -983,7 +983,7 @@ gtk_rc_context_parse_one_file (GtkRcContext *context,
 			       gboolean      reload)
 {
   GtkRcFile *rc_file;
-  struct stat statbuf;
+  GStatBuf statbuf;
   gint saved_priority;
 
   g_return_if_fail (filename != NULL);
@@ -1764,7 +1764,7 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings,
   GtkRcFile *rc_file;
   GSList *tmp_list;
   GtkRcContext *context;
-  struct stat statbuf;
+  GStatBuf statbuf;
 
   g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE);
 
diff --git a/gtk/gtkrecentmanager.c b/gtk/gtkrecentmanager.c
index 609ee1f..1f67c13 100644
--- a/gtk/gtkrecentmanager.c
+++ b/gtk/gtkrecentmanager.c
@@ -2221,7 +2221,7 @@ gboolean
 gtk_recent_info_exists (GtkRecentInfo *info)
 {
   gchar *filename;
-  struct stat stat_buf;
+  GStatBuf stat_buf;
   gboolean retval = FALSE;
   
   g_return_val_if_fail (info != NULL, FALSE);
@@ -2233,7 +2233,7 @@ gtk_recent_info_exists (GtkRecentInfo *info)
   filename = g_filename_from_uri (info->uri, NULL, NULL);
   if (filename)
     {
-      if (stat (filename, &stat_buf) == 0)
+      if (g_stat (filename, &stat_buf) == 0)
         retval = TRUE;
      
       g_free (filename);
diff --git a/gtk/tests/pixbuf-init.c b/gtk/tests/pixbuf-init.c
index 47573ab..5184a38 100644
--- a/gtk/tests/pixbuf-init.c
+++ b/gtk/tests/pixbuf-init.c
@@ -1,15 +1,13 @@
 #include "config.h"
 #include <glib.h>
-
-#include <sys/stat.h>
-#include <stdlib.h>
+#include <glib/gstdio.h>
 
 static gboolean
 file_exists (const char *filename)
 {
-  struct stat statbuf;
+  GStatBuf statbuf;
 
-  return stat (filename, &statbuf) == 0;
+  return g_stat (filename, &statbuf) == 0;
 }
 
 void
diff --git a/gtk/updateiconcache.c b/gtk/updateiconcache.c
index 32c8f41..39e1345 100644
--- a/gtk/updateiconcache.c
+++ b/gtk/updateiconcache.c
@@ -119,7 +119,7 @@ static int check_dir_mtime (const char        *dir,
 gboolean
 is_cache_up_to_date (const gchar *path)
 {
-  struct stat path_stat, cache_stat;
+  GStatBuf path_stat, cache_stat;
   gchar *cache_path;
   int retval; 
   
@@ -1478,7 +1478,7 @@ build_cache (const gchar *path)
 #endif
   GHashTable *files;
   FILE *cache;
-  struct stat path_stat, cache_stat;
+  GStatBuf path_stat, cache_stat;
   struct utimbuf utime_buf;
   GList *directories = NULL;
   int fd;
diff --git a/tests/testfilechooser.c b/tests/testfilechooser.c
index 443f5c3..86cb14d 100644
--- a/tests/testfilechooser.c
+++ b/tests/testfilechooser.c
@@ -21,13 +21,13 @@
 
 #include <string.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <stdlib.h>
 #include <time.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 #include <gtk/gtk.h>
+#include <glib/gstdio.h>
 
 #ifdef G_OS_WIN32
 #  include <io.h>
@@ -189,7 +189,7 @@ my_new_from_file_at_size (const char *filename,
 	GdkPixbufLoader *loader;
 	GdkPixbuf       *pixbuf;
 	int              info[2];
-	struct stat st;
+	GStatBuf st;
 
 	guchar buffer [4096];
 	int length;
@@ -198,7 +198,7 @@ my_new_from_file_at_size (const char *filename,
 	g_return_val_if_fail (filename != NULL, NULL);
         g_return_val_if_fail (width > 0 && height > 0, NULL);
 
-	if (stat (filename, &st) != 0) {
+	if (g_stat (filename, &st) != 0) {
                 int errsv = errno;
 
 		g_set_error (error,
@@ -298,8 +298,8 @@ update_preview_cb (GtkFileChooser *chooser)
 	}
       else
 	{
-	  struct stat buf;
-	  if (stat (filename, &buf) == 0)
+	  GStatBuf buf;
+	  if (g_stat (filename, &buf) == 0)
 	    {
 	      gchar *preview_text;
 	      gchar *size_str;
diff --git a/tests/testgtk.c b/tests/testgtk.c
index ec2c57c..b7ea442 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -35,7 +35,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/stat.h>
 #include <math.h>
 #include <time.h>
 #ifdef HAVE_UNISTD_H
@@ -46,6 +45,7 @@
 #include "gtk/gtk.h"
 #include "gdk/gdk.h"
 #include "gdk/gdkkeysyms.h"
+#include "glib/gstdio.h"
 
 #ifdef G_OS_WIN32
 #define sleep(n) _sleep(n)
@@ -59,9 +59,9 @@
 gboolean
 file_exists (const char *filename)
 {
-  struct stat statbuf;
+  GStatBuf statbuf;
 
-  return stat (filename, &statbuf) == 0;
+  return g_stat (filename, &statbuf) == 0;
 }
 
 GtkWidget *
diff --git a/tests/testtext.c b/tests/testtext.c
index 880eaa7..b9678bf 100644
--- a/tests/testtext.c
+++ b/tests/testtext.c
@@ -20,7 +20,6 @@
 
 #include "config.h"
 #include <stdio.h>
-#include <sys/stat.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
@@ -30,6 +29,7 @@
 
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
+#include <glib/gstdio.h>
 
 #include "prop-editor.h"
 
@@ -2096,9 +2096,9 @@ save_as_ok_func (const char *filename, gpointer data)
 
   if (!buffer->filename || strcmp (filename, buffer->filename) != 0)
     {
-      struct stat statbuf;
+      GStatBuf statbuf;
 
-      if (stat (filename, &statbuf) == 0)
+      if (g_stat (filename, &statbuf) == 0)
 	{
 	  gchar *err = g_strdup_printf ("Ovewrite existing file '%s'?", filename);
 	  gint result = msgbox_run (NULL, err, "Yes", "No", NULL, 1);