nmtui: ESC pressed in the delete connection dialog confirms deletion
Summary
Update: the issue can be reproduced in systems which allow Esc key to close the delete connection dialog. For example, ubuntu does patch newt sources for that (escape_key.patch). Not affected example: fedora.
Due to wrong logic, when a user taps ESC in the delete connection dialog, the connection gets removed.
Problematic code starts with this comment
/**
..
* Returns: which button was clicked: 0 for @button1 or 1 for @button2
*/
int
nmt_newt_choice_dialog(const char *button1, const char *button2, const char *message, ...)
{
..
choice = newtWinChoice(NULL, button1_lc, button2_lc, "%s", msg_lc);
..
return choice;
}
Actually, newtWinChoice
returns 1 for the first button, 2 for the second button and 0 otherwise.
Next, nmt_newt_choice_dialog
is used like this:
void
nmt_remove_connection(NMRemoteConnection *connection)
{
..
int choice;
choice = nmt_newt_choice_dialog(_("Cancel"),
_("Delete"),
_("Are you sure you want to delete the connection '%s'?"),
nm_connection_get_id(NM_CONNECTION(connection)));
if (choice == 1)
return;
g_object_ref(connection);
remove_one_connection(connection);
So, if the user clicks "Cancel" (the first button), nothing happens. In all other cases (second button or ESC), the connection gets removed. Evidently, the condition should be (choice < 2)
.
Version affected
Looking back into history, I see it was so since initial import of nmtui commit on Dec 2, 2013. So, all versions are affected.
Steps to reproduce
- create a dummy connection
- select it in nmtui
- click the "Delete" button
- press ESC
Actual result
The connection got removed.
Expected result
The dialog is closed without removing anything.