mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-04-01 10:10:18 +00:00
Sanitize Linux open env for AppImage, add safer fallbacks
This commit is contained in:
@@ -1308,17 +1308,38 @@ maybe_escape_uri (const char *uri)
|
||||
return g_strdup (uri);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
static gchar **
|
||||
fe_open_url_env_sanitized (void)
|
||||
{
|
||||
gchar **env = g_get_environ ();
|
||||
const char *vars[] = {"LD_LIBRARY_PATH", "LD_PRELOAD", "APPDIR", "APPIMAGE", "ARGV0", NULL};
|
||||
int i;
|
||||
|
||||
for (i = 0; vars[i]; i++)
|
||||
{
|
||||
gchar **tmp_env = env;
|
||||
env = g_environ_unsetenv (tmp_env, vars[i]);
|
||||
if (env != tmp_env)
|
||||
g_strfreev (tmp_env);
|
||||
}
|
||||
|
||||
return env;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
fe_open_url_inner (const char *url)
|
||||
{
|
||||
GError *error = NULL;
|
||||
char *escaped_url = maybe_escape_uri (url);
|
||||
gboolean opened = g_app_info_launch_default_for_uri (escaped_url, NULL, &error);
|
||||
gboolean opened = FALSE;
|
||||
|
||||
#ifdef WIN32
|
||||
opened = g_app_info_launch_default_for_uri (escaped_url, NULL, &error);
|
||||
if (!opened)
|
||||
{
|
||||
g_clear_error (&error);
|
||||
#ifdef WIN32
|
||||
gunichar2 *url_utf16 = g_utf8_to_utf16 (escaped_url, -1, NULL, NULL, NULL);
|
||||
|
||||
if (url_utf16 != NULL)
|
||||
@@ -1326,22 +1347,11 @@ fe_open_url_inner (const char *url)
|
||||
opened = ((INT_PTR) ShellExecuteW (0, L"open", url_utf16, NULL, NULL, SW_SHOWNORMAL)) > 32;
|
||||
g_free (url_utf16);
|
||||
}
|
||||
#else
|
||||
gchar *xdg_open_argv[] = {(gchar *) "xdg-open", escaped_url, NULL};
|
||||
gchar **spawn_env = NULL;
|
||||
|
||||
spawn_env = g_get_environ ();
|
||||
{
|
||||
gchar **tmp_env = spawn_env;
|
||||
spawn_env = g_environ_unsetenv (tmp_env, "LD_LIBRARY_PATH");
|
||||
if (spawn_env != tmp_env)
|
||||
g_strfreev (tmp_env);
|
||||
|
||||
tmp_env = spawn_env;
|
||||
spawn_env = g_environ_unsetenv (tmp_env, "LD_PRELOAD");
|
||||
if (spawn_env != tmp_env)
|
||||
g_strfreev (tmp_env);
|
||||
}
|
||||
#else
|
||||
{
|
||||
gchar *xdg_open_argv[] = {(gchar *) "xdg-open", escaped_url, NULL};
|
||||
gchar **spawn_env = fe_open_url_env_sanitized ();
|
||||
|
||||
if (g_spawn_async (NULL, xdg_open_argv, spawn_env,
|
||||
G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
|
||||
@@ -1354,6 +1364,16 @@ fe_open_url_inner (const char *url)
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
g_strfreev (spawn_env);
|
||||
}
|
||||
|
||||
if (!opened)
|
||||
{
|
||||
opened = g_app_info_launch_default_for_uri (escaped_url, NULL, &error);
|
||||
if (!opened)
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
if (!opened && gtk_show_uri_on_window (NULL, escaped_url, GDK_CURRENT_TIME, &error))
|
||||
{
|
||||
opened = TRUE;
|
||||
@@ -1362,10 +1382,7 @@ fe_open_url_inner (const char *url)
|
||||
{
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
g_strfreev (spawn_env);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!opened)
|
||||
{
|
||||
|
||||
@@ -1888,7 +1888,8 @@ menu_about (GtkWidget *wid, gpointer sess)
|
||||
GtkWidget *license;
|
||||
GtkWidget *close;
|
||||
GtkWidget *actions;
|
||||
GtkWidget *default_close;
|
||||
GList *children;
|
||||
GList *child;
|
||||
static const gchar *empty_people[] = { NULL };
|
||||
theme_manager_attach_window (GTK_WIDGET (dialog));
|
||||
char comment[512];
|
||||
@@ -1917,13 +1918,14 @@ menu_about (GtkWidget *wid, gpointer sess)
|
||||
gtk_about_dialog_set_logo (dialog, pix_zoitechat);
|
||||
gtk_about_dialog_set_copyright (dialog, "\302\251 1998-2010 Peter \305\275elezn\303\275\n\302\251 2009-2014 Berke Viktor\n\302\251 2015-2025 Patrick Griffis\n\302\251 2026 deepend");
|
||||
gtk_about_dialog_set_comments (dialog, comment);
|
||||
default_close = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
|
||||
if (default_close)
|
||||
gtk_widget_destroy (default_close);
|
||||
actions = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
|
||||
children = gtk_container_get_children (GTK_CONTAINER (actions));
|
||||
for (child = children; child; child = child->next)
|
||||
gtk_widget_destroy (GTK_WIDGET (child->data));
|
||||
g_list_free (children);
|
||||
website = gtk_dialog_add_button (GTK_DIALOG (dialog), "Website", GTK_RESPONSE_HELP);
|
||||
license = gtk_dialog_add_button (GTK_DIALOG (dialog), "License", GTK_RESPONSE_APPLY);
|
||||
close = gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Close"), GTK_RESPONSE_CLOSE);
|
||||
actions = gtk_widget_get_parent (close);
|
||||
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (actions), website, TRUE);
|
||||
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (actions), license, TRUE);
|
||||
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (actions), close, FALSE);
|
||||
|
||||
Reference in New Issue
Block a user