Gentoo Archives: gentoo-commits

From: "Alexandre Rostovtsev (tetromino)" <tetromino@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in net-libs/loudmouth/files: loudmouth-1.4.3-invalid-unicode.patch loudmouth-1.4.3-free-before-closed.patch loudmouth-1.4.3-silence-chdir.patch loudmouth-1.4.3-id-tag-in-opening-headers.patch
Date: Wed, 02 Nov 2011 02:56:51
Message-Id: 20111102025640.786322004E@flycatcher.gentoo.org
1 tetromino 11/11/02 02:56:40
2
3 Added: loudmouth-1.4.3-invalid-unicode.patch
4 loudmouth-1.4.3-free-before-closed.patch
5 loudmouth-1.4.3-silence-chdir.patch
6 loudmouth-1.4.3-id-tag-in-opening-headers.patch
7 Log:
8 Add patches fixing rfc-3920 compliance, preventing segfaults and excessive debug messages, and fixing utf-8 validation of incoming messages (bug #389127, many thanks to Dmitry Potapov <potapov.d@×××××.com> for reporting). Also, move to EAPI4 and add USE=static-libs support. The Imendio upstream is gone, so use gnome.org for SRC_URI and set the github repo which is supposedly considered the closest thing to official that loudmouth has these days as the homepage.
9
10 (Portage version: 2.2.0_alpha72/cvs/Linux x86_64)
11
12 Revision Changes Path
13 1.1 net-libs/loudmouth/files/loudmouth-1.4.3-invalid-unicode.patch
14
15 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-libs/loudmouth/files/loudmouth-1.4.3-invalid-unicode.patch?rev=1.1&view=markup
16 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-libs/loudmouth/files/loudmouth-1.4.3-invalid-unicode.patch?rev=1.1&content-type=text/plain
17
18 Index: loudmouth-1.4.3-invalid-unicode.patch
19 ===================================================================
20 From e08dbcca6cf50c834e2fe4e7290cce642903251d Mon Sep 17 00:00:00 2001
21 From: Hermitifier <quantifier666@×××××.com>
22 Date: Mon, 3 Oct 2011 17:06:18 +0200
23 Subject: [PATCH] Protect GMarkup parser against invalid unicode characters
24
25 [Alexandre Rostovtsev <tetromino@g.o>: backport to 1.4.3]
26
27 http://loudmouth.lighthouseapp.com/projects/17276/tickets/61
28 ---
29 loudmouth/lm-parser.c | 94 ++++++++++++++++++++++++++++++++++++++++++++-----
30 1 files changed, 85 insertions(+), 9 deletions(-)
31
32 diff --git a/loudmouth/lm-parser.c b/loudmouth/lm-parser.c
33 index 89f6675..0a61a56 100644
34 --- a/loudmouth/lm-parser.c
35 +++ b/loudmouth/lm-parser.c
36 @@ -43,6 +43,8 @@ struct LmParser {
37
38 GMarkupParser *m_parser;
39 GMarkupParseContext *context;
40 + gchar *incomplete; /* incomplete utf-8 character
41 + found at the end of buffer */
42 };
43
44
45 @@ -233,25 +235,98 @@ lm_parser_new (LmParserMessageFunction function,
46 parser->cur_root = NULL;
47 parser->cur_node = NULL;
48
49 + parser->incomplete = NULL;
50 +
51 return parser;
52 }
53
54 +static gchar *
55 +_lm_parser_make_valid (const gchar *buffer, gchar **incomplete)
56 +{
57 + GString *string;
58 + const gchar *remainder, *invalid;
59 + gint remaining_bytes, valid_bytes;
60 + gunichar code; /*error code for invalid character*/
61 +
62 + g_return_val_if_fail (buffer != NULL, NULL);
63 +
64 + string = NULL;
65 + remainder = buffer;
66 + remaining_bytes = strlen (buffer);
67 +
68 + while (remaining_bytes != 0)
69 + {
70 + if (g_utf8_validate (remainder, remaining_bytes, &invalid))
71 + break;
72 + valid_bytes = invalid - remainder;
73 +
74 + if (string == NULL)
75 + string = g_string_sized_new (remaining_bytes);
76 +
77 + g_string_append_len (string, remainder, valid_bytes);
78 +
79 + remainder = g_utf8_find_next_char(invalid, NULL);
80 + remaining_bytes -= valid_bytes + (remainder - invalid);
81 +
82 + code = g_utf8_get_char_validated (invalid, -1);
83 +
84 + if (code == -1) {
85 + /* A complete but invalid codepoint */
86 + /* append U+FFFD REPLACEMENT CHARACTER */
87 + g_string_append (string, "\357\277\275");
88 +#ifndef LM_NO_DEBUG
89 + g_debug ("invalid character!\n");
90 +#endif
91 + } else if (code == -2) {
92 + /* Beginning of what could be a character */
93 + *incomplete = g_strdup (invalid);
94 +#ifndef LM_NO_DEBUG
95 + g_debug ("incomplete character: %s\n", *incomplete);
96 +#endif
97 +
98 + g_assert (remaining_bytes == 0);
99 + g_assert (*(g_utf8_find_next_char(invalid, NULL)) == '\0');
100 + }
101 + }
102 +
103 + if (string == NULL)
104 + return g_strdup (buffer);
105 +
106 + g_string_append (string, remainder);
107 +
108 + g_assert (g_utf8_validate (string->str, -1, NULL));
109 +
110 + return g_string_free (string, FALSE);
111 +}
112 +
113 +
114 void
115 lm_parser_parse (LmParser *parser, const gchar *string)
116 {
117 + gchar *valid, *completed;
118 g_return_if_fail (parser != NULL);
119
120 - if (!parser->context) {
121 - parser->context = g_markup_parse_context_new (parser->m_parser, 0,
122 - parser, NULL);
123 - }
124 -
125 - if (g_markup_parse_context_parse (parser->context, string,
126 - (gssize)strlen (string), NULL)) {
127 - } else {
128 + if (!parser->context) {
129 + parser->context = g_markup_parse_context_new (parser->m_parser, 0,
130 + parser, NULL);
131 + }
132 +
133 + if (parser->incomplete) {
134 + completed = g_strdup_printf("%s%s", parser->incomplete, string);
135 + g_free(parser->incomplete);
136 + parser->incomplete = NULL;
137 + } else {
138 + completed = g_strdup(string);
139 + }
140 + valid = _lm_parser_make_valid (completed, &parser->incomplete);
141 + g_free(completed);
142 + if (g_markup_parse_context_parse (parser->context, valid,
143 + (gssize)strlen (valid), NULL)) {
144 + } else {
145 g_markup_parse_context_free (parser->context);
146 parser->context = NULL;
147 - }
148 + }
149 + g_free(valid);
150 }
151
152 void
153 @@ -264,6 +339,7 @@ lm_parser_free (LmParser *parser)
154 if (parser->context) {
155 g_markup_parse_context_free (parser->context);
156 }
157 + g_free (parser->incomplete);
158 g_free (parser->m_parser);
159 g_free (parser);
160 }
161 --
162 1.7.7.1
163
164
165
166
167 1.1 net-libs/loudmouth/files/loudmouth-1.4.3-free-before-closed.patch
168
169 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-libs/loudmouth/files/loudmouth-1.4.3-free-before-closed.patch?rev=1.1&view=markup
170 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-libs/loudmouth/files/loudmouth-1.4.3-free-before-closed.patch?rev=1.1&content-type=text/plain
171
172 Index: loudmouth-1.4.3-free-before-closed.patch
173 ===================================================================
174 From ff113220df9073c3e6078487e87b6a7b86e2d952 Mon Sep 17 00:00:00 2001
175 From: Mikael Hallendal <micke@×××××××.com>
176 Date: Sun, 30 Nov 2008 09:27:21 +0100
177 Subject: [PATCH] Don't free connection internals before it's closed. [#34]
178
179 When the connection freed up internal states (in this case the handler
180 lists) before closing itself it segfaulted when trying to unregister the
181 SASL handlers.
182
183 Reported by Julien Puydt.
184 ---
185 loudmouth/lm-connection.c | 30 +++++++++++++++++-------------
186 loudmouth/lm-sasl.c | 18 +++++++++---------
187 2 files changed, 26 insertions(+), 22 deletions(-)
188
189 diff --git a/loudmouth/lm-connection.c b/loudmouth/lm-connection.c
190 index 915c0ad..dda2978 100644
191 --- a/loudmouth/lm-connection.c
192 +++ b/loudmouth/lm-connection.c
193 @@ -191,13 +191,21 @@ connection_free (LmConnection *connection)
194 {
195 int i;
196
197 + /* This needs to be run before starting to free internal states.
198 + * It used to be run after the handlers where freed which lead to a crash
199 + * when the connection was freed prior to running lm_connection_close.
200 + */
201 + if (connection->state >= LM_CONNECTION_STATE_OPENING) {
202 + connection_do_close (connection);
203 + }
204 +
205 g_free (connection->server);
206 g_free (connection->jid);
207 g_free (connection->effective_jid);
208 g_free (connection->stream_id);
209 g_free (connection->resource);
210
211 - if (connection->sasl) {
212 + if (connection->sasl) {
213 lm_sasl_free (connection->sasl);
214 }
215
216 @@ -218,13 +226,9 @@ connection_free (LmConnection *connection)
217
218 g_slist_free (connection->handlers[i]);
219 }
220 -
221 g_hash_table_destroy (connection->id_handlers);
222 - if (connection->state >= LM_CONNECTION_STATE_OPENING) {
223 - connection_do_close (connection);
224 - }
225
226 - if (connection->open_cb) {
227 + if (connection->open_cb) {
228 _lm_utils_free_callback (connection->open_cb);
229 }
230
231 @@ -2030,11 +2034,11 @@ lm_connection_unregister_message_handler (LmConnection *connection,
232 g_return_if_fail (handler != NULL);
233 g_return_if_fail (type != LM_MESSAGE_TYPE_UNKNOWN);
234
235 - for (l = connection->handlers[type]; l; l = l->next) {
236 - HandlerData *hd = (HandlerData *) l->data;
237 -
238 + for (l = connection->handlers[type]; l; l = l->next) {
239 + HandlerData *hd = (HandlerData *) l->data;
240 +
241 if (handler == hd->handler) {
242 - connection->handlers[type] = g_slist_remove_link (connection->handlers[type], l);
243 + connection->handlers[type] = g_slist_remove_link (connection->handlers[type], l);
244 g_slist_free (l);
245 lm_message_handler_unref (hd->handler);
246 g_free (hd);
247 @@ -2140,7 +2144,7 @@ lm_connection_ref (LmConnection *connection)
248 g_return_val_if_fail (connection != NULL, NULL);
249
250 connection->ref_count++;
251 -
252 +
253 return connection;
254 }
255
256 @@ -2157,8 +2161,8 @@ lm_connection_unref (LmConnection *connection)
257 g_return_if_fail (connection != NULL);
258
259 connection->ref_count--;
260 -
261 +
262 if (connection->ref_count == 0) {
263 - connection_free (connection);
264 + connection_free (connection);
265 }
266 }
267 diff --git a/loudmouth/lm-sasl.c b/loudmouth/lm-sasl.c
268 index 42ee0e1..e6a72f5 100644
269 --- a/loudmouth/lm-sasl.c
270 +++ b/loudmouth/lm-sasl.c
271 @@ -807,27 +807,27 @@ lm_sasl_free (LmSASL *sasl)
272 g_free (sasl->server);
273
274 if (sasl->features_cb) {
275 - lm_connection_unregister_message_handler (sasl->connection,
276 - sasl->features_cb,
277 - LM_MESSAGE_TYPE_STREAM_FEATURES);
278 + lm_connection_unregister_message_handler (sasl->connection,
279 + sasl->features_cb,
280 + LM_MESSAGE_TYPE_STREAM_FEATURES);
281 }
282
283 if (sasl->challenge_cb) {
284 lm_connection_unregister_message_handler (sasl->connection,
285 - sasl->challenge_cb,
286 - LM_MESSAGE_TYPE_CHALLENGE);
287 + sasl->challenge_cb,
288 + LM_MESSAGE_TYPE_CHALLENGE);
289 }
290
291 if (sasl->success_cb) {
292 lm_connection_unregister_message_handler (sasl->connection,
293 - sasl->success_cb,
294 - LM_MESSAGE_TYPE_SUCCESS);
295 + sasl->success_cb,
296 + LM_MESSAGE_TYPE_SUCCESS);
297 }
298
299 if (sasl->failure_cb) {
300 lm_connection_unregister_message_handler (sasl->connection,
301 - sasl->failure_cb,
302 - LM_MESSAGE_TYPE_FAILURE);
303 + sasl->failure_cb,
304 + LM_MESSAGE_TYPE_FAILURE);
305 }
306
307 g_free (sasl);
308 --
309 1.7.7.1
310
311
312
313
314 1.1 net-libs/loudmouth/files/loudmouth-1.4.3-silence-chdir.patch
315
316 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-libs/loudmouth/files/loudmouth-1.4.3-silence-chdir.patch?rev=1.1&view=markup
317 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-libs/loudmouth/files/loudmouth-1.4.3-silence-chdir.patch?rev=1.1&content-type=text/plain
318
319 Index: loudmouth-1.4.3-silence-chdir.patch
320 ===================================================================
321 From 4d8a5ea64abb65ed086efc3e32125c529068acbe Mon Sep 17 00:00:00 2001
322 From: Mikael Hallendal <micke@×××××××.com>
323 Date: Wed, 19 Nov 2008 10:16:40 +0100
324 Subject: [PATCH] Silence chdir by catching return value
325
326 ---
327 loudmouth/asyncns.c | 3 ++-
328 1 files changed, 2 insertions(+), 1 deletions(-)
329
330 diff --git a/loudmouth/asyncns.c b/loudmouth/asyncns.c
331 index 9b238fa..55cb471 100644
332 --- a/loudmouth/asyncns.c
333 +++ b/loudmouth/asyncns.c
334 @@ -382,6 +382,7 @@ static int process_worker(int in_fd, int out_fd) {
335 int have_death_sig = 0;
336 assert(in_fd > 2);
337 assert(out_fd > 2);
338 + int no_warn;
339
340 close(0);
341 close(1);
342 @@ -391,7 +392,7 @@ static int process_worker(int in_fd, int out_fd) {
343 open("/dev/null", O_WRONLY);
344 open("/dev/null", O_WRONLY);
345
346 - chdir("/");
347 + no_warn = chdir("/");
348
349 if (geteuid() == 0) {
350 struct passwd *pw;
351 --
352 1.7.7.1
353
354
355
356
357 1.1 net-libs/loudmouth/files/loudmouth-1.4.3-id-tag-in-opening-headers.patch
358
359 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-libs/loudmouth/files/loudmouth-1.4.3-id-tag-in-opening-headers.patch?rev=1.1&view=markup
360 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-libs/loudmouth/files/loudmouth-1.4.3-id-tag-in-opening-headers.patch?rev=1.1&content-type=text/plain
361
362 Index: loudmouth-1.4.3-id-tag-in-opening-headers.patch
363 ===================================================================
364 From 6f3a168d985d37af42e747412b5d6d427b4d1ab8 Mon Sep 17 00:00:00 2001
365 From: Will Thompson <will.thompson@××××××××××××.uk>
366 Date: Wed, 5 Nov 2008 23:19:42 +0100
367 Subject: [PATCH] Don't append the 'id'-tag in opening stream headers. [#30]
368
369 According to RFC 3920 (section 4.4) the id attribute SHOULD NOT be added
370 by the initiating party.
371
372 [#30 responsible:Hallski state:resolved milestone:Loudmouth 1.4.4 tagged:committed]
373 ---
374 loudmouth/lm-message.c | 8 +++++---
375 1 files changed, 5 insertions(+), 3 deletions(-)
376
377 diff --git a/loudmouth/lm-message.c b/loudmouth/lm-message.c
378 index a7d1b46..e2fdcc2 100644
379 --- a/loudmouth/lm-message.c
380 +++ b/loudmouth/lm-message.c
381 @@ -223,9 +223,11 @@ lm_message_new (const gchar *to, LmMessageType type)
382
383 m->node = _lm_message_node_new (_lm_message_type_to_string (type));
384
385 - id = _lm_utils_generate_id ();
386 - lm_message_node_set_attribute (m->node, "id", id);
387 - g_free (id);
388 + if (type != LM_MESSAGE_TYPE_STREAM) {
389 + id = _lm_utils_generate_id ();
390 + lm_message_node_set_attribute (m->node, "id", id);
391 + g_free (id);
392 + }
393
394 if (to) {
395 lm_message_node_set_attribute (m->node, "to", to);
396 --
397 1.7.7.1