[caribou] libcaribou: avoid integer overflow



commit 4fd57133bb0f835f0f5847a6b25c580793ecc5d9
Author: Daiki Ueno <ueno unixuser org>
Date:   Thu Jan 10 18:19:37 2013 +0900

    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 files changed, 5 insertions(+), 5 deletions(-)
---
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;
                     }
                 }
             }



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