File: CVE-2026-2604.patch

package info (click to toggle)
evolution-data-server 3.56.2-8
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 47,108 kB
  • sloc: ansic: 365,415; xml: 578; cpp: 482; perl: 297; sh: 62; makefile: 60; python: 35; javascript: 29
file content (168 lines) | stat: -rw-r--r-- 6,247 bytes parent folder | 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
Backport of:

From afa12b6ba502e5acaa431415aa3b939ddb377382 Mon Sep 17 00:00:00 2001
From: Milan Crha <mcrha@redhat.com>
Date: Mon, 16 Feb 2026 18:20:34 +0100
Subject: [PATCH] I#627 - Canonicalize path before local cache file removal

Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/627
---
 .../backends/file/e-book-backend-file.c       |  2 +-
 .../libedata-book/e-book-meta-backend.c       |  2 +-
 src/calendar/libedata-cal/e-cal-cache.c       |  2 +-
 src/libedataserver/e-data-server-util.c       | 42 ++++++++++++++++++
 src/libedataserver/e-data-server-util.h       |  2 +
 tests/libedataserver/libedataserver-test.c    | 43 +++++++++++++++++++
 6 files changed, 90 insertions(+), 3 deletions(-)

--- a/src/addressbook/backends/file/e-book-backend-file.c
+++ b/src/addressbook/backends/file/e-book-backend-file.c
@@ -392,7 +392,7 @@ maybe_delete_uri (EBookBackendFile *bf,
 	/* If the file is in our path it belongs to us and we need to delete it.
 	 */
 	if (bf->priv->photo_dirname &&
-	    !strncmp (bf->priv->photo_dirname, filename, strlen (bf->priv->photo_dirname))) {
+	    e_util_filename_is_in_path (filename, bf->priv->photo_dirname)) {
 
 		d (g_print ("Deleting uri file: %s\n", filename));
 
--- a/src/addressbook/libedata-book/e-book-meta-backend.c
+++ b/src/addressbook/libedata-book/e-book-meta-backend.c
@@ -583,7 +583,7 @@ ebmb_gather_photos_local_filenames (EBoo
 				gchar *filename;
 
 				filename = g_filename_from_uri (url, NULL, NULL);
-				if (filename && g_str_has_prefix (filename, cache_path))
+				if (filename && e_util_filename_is_in_path (filename, cache_path))
 					filenames = g_slist_prepend (filenames, filename);
 				else
 					g_free (filename);
--- a/src/calendar/libedata-cal/e-cal-cache.c
+++ b/src/calendar/libedata-cal/e-cal-cache.c
@@ -3707,7 +3707,7 @@ e_cal_cache_delete_attachments (ECalCach
 						if (!cache_dirname)
 							cache_dirname = g_path_get_dirname (e_cache_get_filename (E_CACHE (cal_cache)));
 
-						if (g_str_has_prefix (filename, cache_dirname) &&
+						if (e_util_filename_is_in_path (filename, cache_dirname) &&
 						    g_unlink (filename) == -1) {
 							/* Ignore these errors */
 						}
--- a/src/libedataserver/e-data-server-util.c
+++ b/src/libedataserver/e-data-server-util.c
@@ -3152,3 +3152,45 @@ e_util_guess_source_is_readonly	(ESource
 
 	return res;
 }
+
+/**
+ * e_util_filename_is_in_path:
+ * @filename: a filename
+ * @path: an expected path
+ *
+ * Checks whether the @filename is stored under @path.
+ * It use canonicalized form of the paths before comparing them.
+ * Both the @filename and @path are expected to be absolute paths,
+ * is not, %FALSE is returned.
+ *
+ * Returns: whether the @filename is stored under @path
+ *
+ * Since: 3.60
+ **/
+gboolean
+e_util_filename_is_in_path (const gchar *filename,
+			    const gchar *path)
+{
+	gchar *canon_filename, *canon_path;
+	gsize path_len;
+	gboolean res;
+
+	g_return_val_if_fail (filename != NULL, FALSE);
+	g_return_val_if_fail (path != NULL, FALSE);
+
+	if (!g_path_is_absolute (filename) ||
+	    !g_path_is_absolute (path))
+		return FALSE;
+
+	canon_filename = g_canonicalize_filename (filename, NULL);
+	canon_path = g_canonicalize_filename (path, NULL);
+	path_len = strlen (canon_path);
+
+	res = path_len > 0 && g_str_has_prefix (canon_filename, canon_path) &&
+		canon_filename[path_len] == G_DIR_SEPARATOR;
+
+	g_free (canon_filename);
+	g_free (canon_path);
+
+	return res;
+}
--- a/src/libedataserver/e-data-server-util.h
+++ b/src/libedataserver/e-data-server-util.h
@@ -265,6 +265,8 @@ void		e_util_change_uri_port		(GUri **in
 						 gint port);
 void		e_util_call_malloc_trim		(void);
 gboolean	e_util_guess_source_is_readonly	(struct _ESource *source);
+gboolean	e_util_filename_is_in_path	(const gchar *filename,
+						 const gchar *path);
 
 G_END_DECLS
 
--- a/tests/libedataserver/libedataserver-test.c
+++ b/tests/libedataserver/libedataserver-test.c
@@ -119,6 +119,43 @@ test_parse_date (ETestServerFixture *fix
 	}
 }
 
+static void
+test_filename_is_in_path (ETestServerFixture *fixture,
+			  gconstpointer user_data)
+{
+	struct _tests {
+		const gchar *filename;
+		const gchar *path;
+		gboolean expected;
+	} tests[] = {
+		{ "/home/user/.cache/dir/", "/home/user/.cache/dir", FALSE },
+		{ "/home/user/.cache/dir", "/home/user/.cache/dir", FALSE },
+		{ "/home/user/.cache/dir", "/home/user/.cache/dir/", FALSE },
+		{ "/home/user/.cache/dir/", "/home/user/.cache/dir/", FALSE },
+		{ "/home/user/.cache/dir/file.txt", "/home/user/.cache/dir/", TRUE },
+		{ "/home/user/.cache/dir/file.txt", "/home/user/.cache/dir", TRUE },
+		{ "/home/user/.cache/dir/subdir/file.txt", "/home/user/.cache/dir/", TRUE },
+		{ "/home/user/.cache/dir/subdir/file.txt", "/home/user/.cache/dir", TRUE },
+		{ "/home/user/.cache/dir/./file.txt", "/home/user/.cache/dir/", TRUE },
+		{ "/home/user/.cache/dir/./file.txt", "/home/user/.cache/dir", TRUE },
+		{ "/home/user/.cache/dir/../file.txt", "/home/user/.cache/dir/", FALSE },
+		{ "/home/user/.cache/dir/../file.txt", "/home/user/.cache/dir", FALSE },
+		{ "/home/user/.cache/dir/.././dir/../../.cache/./dir/file.txt", "/home/user/.cache/dir/", TRUE },
+		{ "/home/user/.cache/dir/.././dir/../../.cache/./dir/file.txt", "/home/user/.cache/dir", TRUE },
+		{ "/home/user/.cache/dir/../../../../var/lib/file.txt", "/home/user/.cache/dir/", FALSE },
+		{ "/home/user/.cache/dir/../../../../var/lib/file.txt", "/home/user/.cache/dir", FALSE },
+		{ "./file.txt", "/home/user/.cache/dir", FALSE },
+		{ "../file.txt", "/home/user/.cache/dir", FALSE }
+	};
+	gint ii;
+
+	for (ii = 0; ii < G_N_ELEMENTS (tests); ii++) {
+		gboolean result = e_util_filename_is_in_path (tests[ii].filename, tests[ii].path);
+
+		g_assert_cmpint ((result ? 1 : 0), ==, (tests[ii].expected ? 1 : 0));
+	}
+}
+
 gint
 main (gint argc,
       gchar **argv)
@@ -138,6 +175,12 @@ main (gint argc,
 		e_test_server_utils_setup,
 		test_parse_date,
 		e_test_server_utils_teardown);
+	g_test_add (
+		"/libedataserver-test/FilenameIsInPath",
+		ETestServerFixture, &test_closure,
+		e_test_server_utils_setup,
+		test_filename_is_in_path,
+		e_test_server_utils_teardown);
 
 	return e_test_server_utils_run (argc, argv);
 }