Make regexp patterns for matching uris thread safe (fixes NB#108791)
[modest] / src / modest-text-utils.c
index 614db37..93e51ee 100644 (file)
@@ -109,7 +109,7 @@ struct _url_match_t {
 
 /* note: match MARK_AMP_URI_STR as well, because after txt->html, a '&' will look like $(MARK_AMP_URI_STR)"amp;" */
 #define MAIL_VIEWER_URL_MATCH_PATTERNS  {                              \
-       { "(file|rtsp|http|ftp|https|mms|mmsh|webcal|feed|rtsp|rdp|lastfm|sip)://[-a-z0-9_$.+!*(),;:@%=?/~#" MARK_AMP_URI_STR \
+       { "(feed:|)(file|rtsp|http|ftp|https|mms|mmsh|webcal|feed|rtsp|rdp|lastfm|sip)://[-a-z0-9_$.+!*(),;:@%=?/~#" MARK_AMP_URI_STR \
                        "]+[-a-z0-9_$%" MARK_AMP_URI_STR "=?/~#]",      \
          NULL, NULL },\
        { "www\\.[-a-z0-9_$.+!*(),;:@%=?/~#" MARK_AMP_URI_STR "]+[-a-z0-9_$%" MARK_AMP_URI_STR "=?/~#]",\
@@ -286,6 +286,8 @@ modest_text_utils_strftime(char *s, gsize max, const char *fmt, time_t timet)
           garbage in the s variable */
        if (s)
                s[0] = '\0';
+       else
+               return 0;
 
        /* does not work on old maemo glib: 
         *   g_date_set_time_t (&date, timet);
@@ -1016,7 +1018,7 @@ modest_text_utils_quote_html (const gchar *text,
                }
                quote_html_add_to_gstring (result_string, cite);
                quoted_text = g_string_new ("");
-               quoted_text = modest_text_utils_quote_body (quoted_text, text, ">", limit);
+               quoted_text = modest_text_utils_quote_body (quoted_text, (text) ? text : "", ">", limit);
                quote_html_add_to_gstring (result_string, quoted_text->str);
                g_string_free (quoted_text, TRUE);
                if (attachments) {
@@ -1040,6 +1042,7 @@ cmp_offsets_reverse (const url_match_t *match1, const url_match_t *match2)
 
 static gint url_matches_block = 0;
 static url_match_pattern_t patterns[] = MAIL_VIEWER_URL_MATCH_PATTERNS;
+static GMutex *url_patterns_mutex = NULL;
 
 
 static gboolean
@@ -1074,17 +1077,25 @@ free_patterns ()
 void
 modest_text_utils_hyperlinkify_begin (void)
 {
+
+       if (url_patterns_mutex == NULL) {
+               url_patterns_mutex = g_mutex_new ();
+       }
+       g_mutex_lock (url_patterns_mutex);
        if (url_matches_block == 0)
                compile_patterns ();
        url_matches_block ++;
+       g_mutex_unlock (url_patterns_mutex);
 }
 
 void
 modest_text_utils_hyperlinkify_end (void)
 {
+       g_mutex_lock (url_patterns_mutex);
        url_matches_block--;
        if (url_matches_block <= 0)
                free_patterns ();
+       g_mutex_unlock (url_patterns_mutex);
 }