From 4fd57133bb0f835f0f5847a6b25c580793ecc5d9 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Thu, 10 Jan 2013 18:19:37 +0900 Subject: libcaribou: avoid integer overflow Since Xkb.Desc.{min,max}_keycode and Xkb.SymMap.width are defined as uchar, for-loops over them with an uchar index may not stop, if the upper bound is uchar.MAX or the lower bound is 0. https://bugzilla.gnome.org/show_bug.cgi?id=691463 --- libcaribou/xadapter.vala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'libcaribou') diff --git a/libcaribou/xadapter.vala b/libcaribou/xadapter.vala index 62ec4cc..c7c314d 100644 --- a/libcaribou/xadapter.vala +++ b/libcaribou/xadapter.vala @@ -127,9 +127,9 @@ namespace Caribou { } private uchar keysym_to_modifier (uint keyval) { - for (var i = xkbdesc.min_key_code; i <= xkbdesc.max_key_code; i++) { + for (int i = xkbdesc.min_key_code; i <= xkbdesc.max_key_code; i++) { unowned Xkb.SymMap symmap = xkbdesc.map.key_sym_map[i]; - for (var j = 0; + for (int j = 0; j < symmap.width * (symmap.group_info & 0x0f); j++) if (xkbdesc.map.syms[symmap.offset + j] == keyval) @@ -139,12 +139,12 @@ namespace Caribou { } private uchar get_reserved_keycode () { - uchar i; + int i; unowned Xkb.Desc xkbdesc = this.xkbdesc; for (i = xkbdesc.max_key_code; i >= xkbdesc.min_key_code; --i) { if (xkbdesc.map.key_sym_map[i].kt_index[0] == Xkb.OneLevelIndex) { - if (this.xdisplay.keycode_to_keysym (i, 0) != 0) { + if (this.xdisplay.keycode_to_keysym ((uchar) i, 0) != 0) { Gdk.error_trap_push (); this.xdisplay.grab_key (i, 0, Gdk.x11_get_default_root_xwindow (), true, @@ -153,7 +153,7 @@ namespace Caribou { this.xdisplay.ungrab_key ( i, 0, Gdk.x11_get_default_root_xwindow ()); if (Gdk.error_trap_pop () == 0) - return i; + return (uchar) i; } } } -- cgit v1.2.1