[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 01/22: Fix crash with invalid utf8 encoding.

noreply at xfce.org noreply at xfce.org
Sat Aug 20 18:35:04 CEST 2016


This is an automated email from the git hooks/post-receive script.

gottcode pushed a commit to annotated tag v1.4.1
in repository panel-plugins/xfce4-whiskermenu-plugin.

commit 6c8919e1a61c0e787a8798ea1f57ddcc4d72682a
Author: Graeme Gott <graeme at gottcode.org>
Date:   Tue Nov 18 11:32:36 2014 -0500

    Fix crash with invalid utf8 encoding.
---
 panel-plugin/launcher.cpp | 55 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 35 insertions(+), 20 deletions(-)

diff --git a/panel-plugin/launcher.cpp b/panel-plugin/launcher.cpp
index a9a6a8f..2ed8c57 100644
--- a/panel-plugin/launcher.cpp
+++ b/panel-plugin/launcher.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Graeme Gott <graeme at gottcode.org>
+ * Copyright (C) 2013, 2014 Graeme Gott <graeme at gottcode.org>
  *
  * This library is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,6 +27,33 @@ using namespace WhiskerMenu;
 
 //-----------------------------------------------------------------------------
 
+static std::string normalize(const gchar* string)
+{
+	std::string result;
+
+	gchar* normalized = g_utf8_normalize(string, -1, G_NORMALIZE_DEFAULT);
+	if (G_UNLIKELY(!normalized))
+	{
+		return result;
+	}
+
+	gchar* utf8 = g_utf8_casefold(normalized, -1);
+	if (G_UNLIKELY(!utf8))
+	{
+		g_free(normalized);
+		return result;
+	}
+
+	result = utf8;
+
+	g_free(utf8);
+	g_free(normalized);
+
+	return result;
+}
+
+//-----------------------------------------------------------------------------
+
 static void replace_with_quoted_string(std::string& command, size_t& index, const gchar* unquoted)
 {
 	if (!exo_str_is_empty(unquoted))
@@ -111,13 +138,13 @@ Launcher::Launcher(GarconMenuItem* item) :
 
 	// Fetch text
 	const gchar* name = garcon_menu_item_get_name(m_item);
-	if (G_UNLIKELY(!name))
+	if (G_UNLIKELY(!name) || !g_utf8_validate(name, -1, NULL))
 	{
 		name = "";
 	}
 
 	const gchar* generic_name = garcon_menu_item_get_generic_name(m_item);
-	if (G_UNLIKELY(!generic_name))
+	if (G_UNLIKELY(!generic_name) || !g_utf8_validate(generic_name, -1, NULL))
 	{
 		generic_name = "";
 	}
@@ -128,18 +155,14 @@ Launcher::Launcher(GarconMenuItem* item) :
 	if (wm_settings->launcher_show_description)
 	{
 		const gchar* details = garcon_menu_item_get_comment(m_item);
-		if (!details)
+		if (!details || !g_utf8_validate(details, -1, NULL))
 		{
 			details = generic_name;
 		}
 		set_text(g_markup_printf_escaped("%s<b>%s</b>\n%s%s", direction, m_display_name, direction, details));
 
 		// Create search text for comment
-		gchar* normalized = g_utf8_normalize(details, -1, G_NORMALIZE_DEFAULT);
-		gchar* utf8 = g_utf8_casefold(normalized, -1);
-		m_search_comment = utf8;
-		g_free(utf8);
-		g_free(normalized);
+		m_search_comment = normalize(details);
 	}
 	else
 	{
@@ -147,21 +170,13 @@ Launcher::Launcher(GarconMenuItem* item) :
 	}
 
 	// Create search text for display name
-	gchar* normalized = g_utf8_normalize(m_display_name, -1, G_NORMALIZE_DEFAULT);
-	gchar* utf8 = g_utf8_casefold(normalized, -1);
-	m_search_name = utf8;
-	g_free(utf8);
-	g_free(normalized);
+	m_search_name = normalize(m_display_name);
 
 	// Create search text for command
 	const gchar* command = garcon_menu_item_get_command(m_item);
-	if (!exo_str_is_empty(command))
+	if (!exo_str_is_empty(command) && g_utf8_validate(command, -1, NULL))
 	{
-		normalized = g_utf8_normalize(command, -1, G_NORMALIZE_DEFAULT);
-		utf8 = g_utf8_casefold(normalized, -1);
-		m_search_command = utf8;
-		g_free(utf8);
-		g_free(normalized);
+		m_search_command = normalize(command);
 	}
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list