[network-manager-applet] utils: fix editor crash when context-menu's "Paste" item is used (rh #1089199)



commit fbdf9028812078efd77edf176fc3f05f9f089a3e
Author: Jiří Klimeš <jklimes redhat com>
Date:   Wed Apr 23 12:45:19 2014 +0200

    utils: fix editor crash when context-menu's "Paste" item is used (rh #1089199)
    
    When a user used "Paste" item from right-click context menu to copy a password
    to "Password" GtkEntry in "Wi-Fi Security" tab, the editor crashed.
    The reason was that we supposed that "pasword storage" menu is the only menu
    attached to the entry. But there can be other menus attached, like the
    right-click context menu. We fix that by marking "password storage" popup menu
    to be able to identify it and not to mix up the menus.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1089199

 src/utils/utils.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/src/utils/utils.c b/src/utils/utils.c
index a499758..269abe3 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -355,6 +355,8 @@ icon_release_cb (GtkEntry *entry,
        }
 }
 
+#define PASSWORD_STORAGE_MENU_TAG "password-storage-menu"
+
 /**
  * Add secondary icon and create popup menu for password entry.
  **/
@@ -372,6 +374,7 @@ utils_setup_password_storage (NMConnection *connection,
 
        gtk_entry_set_icon_from_icon_name (GTK_ENTRY (passwd_entry), GTK_ENTRY_ICON_SECONDARY, 
"document-save");
        popup_menu = gtk_menu_new ();
+       g_object_set_data (G_OBJECT (popup_menu), PASSWORD_STORAGE_MENU_TAG, GUINT_TO_POINTER (TRUE));
        group = NULL;
        item1 = gtk_radio_menu_item_new_with_mnemonic (group, _("Store the password only for this _user"));
        group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item1));
@@ -432,19 +435,27 @@ utils_update_password_storage (NMSetting *setting,
                                GtkWidget *passwd_entry,
                                const char *password_flags_name)
 {
-       GList *menu;
+       GList *menu_list, *iter;
+       GtkWidget *menu = NULL;
 
        /* Update secret flags (WEP_KEY_FLAGS, PSK_FLAGS, ...) in the security setting */
        nm_setting_set_secret_flags (setting, password_flags_name, secret_flags, NULL);
 
+       menu_list = gtk_menu_get_for_attach_widget (passwd_entry);
+       for (iter = menu_list; iter; iter = g_list_next (iter)) {
+               if (g_object_get_data (G_OBJECT (iter->data), PASSWORD_STORAGE_MENU_TAG)) {
+                       menu = iter->data;
+                       break;
+               }
+       }
+
        /* Update password-storage popup menu to reflect secret flags */
-       menu = gtk_menu_get_for_attach_widget (passwd_entry);
-       if (menu && menu->data) {
+       if (menu) {
                GtkRadioMenuItem *item, *item_user, *item_system;
                GSList *group;
 
                /* radio menu group list contains the menu items in reverse order */
-               item = (GtkRadioMenuItem *) gtk_menu_get_active (GTK_MENU (menu->data));
+               item = (GtkRadioMenuItem *) gtk_menu_get_active (GTK_MENU (menu));
                group = gtk_radio_menu_item_get_group (item);
                item_system = group->data;
                item_user = group->next->data;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]