keybindings: Avoid using unitialized memory and grabbing random keys

meta_parse_accelerator() considers 0 length accelerator strings as
valid, meaning that the keybinding should be disabled. Unfortunately,
it doesn't initialize the MetaKeyCombo so if the caller doesn't
initialize it either, we end up using random values and possibly
grabbing random keys.

https://bugzilla.gnome.org/show_bug.cgi?id=766270
This commit is contained in:
Rui Matos 2016-05-11 18:07:49 +02:00
parent 434f22e820
commit e160babe3f
2 changed files with 11 additions and 3 deletions

View File

@ -1379,8 +1379,8 @@ meta_display_grab_accelerator (MetaDisplay *display,
MetaKeyBindingManager *keys = &display->key_binding_manager; MetaKeyBindingManager *keys = &display->key_binding_manager;
MetaKeyBinding *binding; MetaKeyBinding *binding;
MetaKeyGrab *grab; MetaKeyGrab *grab;
MetaKeyCombo combo; MetaKeyCombo combo = { 0 };
MetaResolvedKeyCombo resolved_combo; MetaResolvedKeyCombo resolved_combo = { 0 };
if (!meta_parse_accelerator (accelerator, &combo)) if (!meta_parse_accelerator (accelerator, &combo))
{ {

View File

@ -326,6 +326,10 @@ gboolean
meta_parse_accelerator (const char *accel, meta_parse_accelerator (const char *accel,
MetaKeyCombo *combo) MetaKeyCombo *combo)
{ {
g_return_val_if_fail (combo != NULL, FALSE);
*combo = (MetaKeyCombo) { 0 };
if (!accel[0] || strcmp (accel, "disabled") == 0) if (!accel[0] || strcmp (accel, "disabled") == 0)
return TRUE; return TRUE;
@ -336,7 +340,11 @@ gboolean
meta_parse_modifier (const char *accel, meta_parse_modifier (const char *accel,
MetaVirtualModifier *mask) MetaVirtualModifier *mask)
{ {
MetaKeyCombo combo; MetaKeyCombo combo = { 0 };
g_return_val_if_fail (mask != NULL, FALSE);
*mask = 0;
if (accel == NULL || !accel[0] || strcmp (accel, "disabled") == 0) if (accel == NULL || !accel[0] || strcmp (accel, "disabled") == 0)
return TRUE; return TRUE;