From 6f21c77c87bc15a9aea1575d2f433c22dbaf12a3 Mon Sep 17 00:00:00 2001 From: Marcin Krol Date: Tue, 6 Oct 2015 07:05:21 +0000 Subject: [PATCH] - fix segmentation faults in search functions --- mc-search-segv.patch | 77 ++++++++++++++++++++++++++++++++++++++++++++ mc.spec | 5 ++- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 mc-search-segv.patch diff --git a/mc-search-segv.patch b/mc-search-segv.patch new file mode 100644 index 0000000..8d20ab9 --- /dev/null +++ b/mc-search-segv.patch @@ -0,0 +1,77 @@ +diff --git a/lib/search/regex.c b/lib/search/regex.c +index f6eb24e..53e3b6f 100644 +--- a/lib/search/regex.c ++++ b/lib/search/regex.c +@@ -249,6 +249,60 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const GString * as + + /* --------------------------------------------------------------------------------------------- */ + ++#ifdef SEARCH_TYPE_GLIB ++/* Glib doesn't like invalid UTF-8 so sanitize it first: ticket 3449. ++ * Be careful: there might be embedded NULs in the strings. */ ++static gboolean ++mc_search__g_regex_match_full_safe (const GRegex * regex, ++ const gchar * string, ++ gssize string_len, ++ gint start_position, ++ GRegexMatchFlags match_options, ++ GMatchInfo ** match_info, GError ** error) ++{ ++ char *string_safe, *p, *end; ++ gboolean ret; ++ ++ if ((g_regex_get_compile_flags (regex) & G_REGEX_RAW) ++ || g_utf8_validate (string, string_len, NULL)) ++ { ++ return g_regex_match_full (regex, string, string_len, start_position, match_options, ++ match_info, error); ++ } ++ ++ if (string_len < 0) ++ { ++ string_len = strlen (string); ++ } ++ p = string_safe = g_strndup (string, string_len); ++ end = p + string_len; ++ ++ while (p < end) ++ { ++ gunichar c = g_utf8_get_char_validated (p, -1); ++ if (c != (gunichar) (-1) && c != (gunichar) (-2)) ++ { ++ p = g_utf8_next_char (p); ++ } ++ else ++ { ++ /* U+FFFD would be the proper choice, but then we'd have to ++ maintain mapping between old and new offsets. ++ So rather do a byte by byte replacement. */ ++ *p++ = '\0'; ++ } ++ } ++ ++ ret = ++ g_regex_match_full (regex, string_safe, string_len, start_position, match_options, ++ match_info, error); ++ g_free (string_safe); ++ return ret; ++} ++#endif /* SEARCH_TYPE_GLIB */ ++ ++/* --------------------------------------------------------------------------------------------- */ ++ + static mc_search__found_cond_t + mc_search__regex_found_cond_one (mc_search_t * lc_mc_search, mc_search_regex_t * regex, + GString * search_str) +@@ -256,8 +310,9 @@ mc_search__regex_found_cond_one (mc_search_t * lc_mc_search, mc_search_regex_t * + #ifdef SEARCH_TYPE_GLIB + GError *mcerror = NULL; + +- if (!g_regex_match_full (regex, search_str->str, search_str->len, 0, G_REGEX_MATCH_NEWLINE_ANY, +- &lc_mc_search->regex_match_info, &mcerror)) ++ if (!mc_search__g_regex_match_full_safe ++ (regex, search_str->str, search_str->len, 0, G_REGEX_MATCH_NEWLINE_ANY, ++ &lc_mc_search->regex_match_info, &mcerror)) + { + g_match_info_free (lc_mc_search->regex_match_info); + lc_mc_search->regex_match_info = NULL; diff --git a/mc.spec b/mc.spec index 43d16f7..4e65dfd 100644 --- a/mc.spec +++ b/mc.spec @@ -19,7 +19,7 @@ Summary(uk.UTF-8): Диспетчер файлів Midnight Commander Summary(zh_CN.UTF-8): 一个方便实用的文件管理器和虚拟Shell Name: mc Version: 4.8.14 -Release: 1 +Release: 2 Epoch: 1 License: GPL v3+ Group: Applications/Shells @@ -36,6 +36,8 @@ Patch4: %{name}-confirm-exit.patch Patch5: %{name}-noperl-vfs.patch # at now syntax highligthing for PLD-update-TODO and CVSROOT/users Patch6: %{name}-pld-developerfriendly.patch +# https://www.midnight-commander.org/ticket/3449 +Patch7: %{name}-search-segv.patch URL: http://www.midnight-commander.org/ BuildRequires: autoconf >= 2.60 BuildRequires: automake >= 1.5 @@ -165,6 +167,7 @@ tar, zip ve RPM dosyalarının içeriklerini gösterebilmesidir. %patch4 -p1 %{!?with_perl_vfs:%patch5 -p1} %patch6 -p1 +%patch7 -p1 %{__rm} po/stamp-po -- 2.46.0