x11/motif: avoid a bad out-of-bounds array access that crashes xpdf when

searching for non-UTF-7.

Reported and tested by Walter Alejandro Iglesias

ok matthieu
This commit is contained in:
tb 2022-11-07 18:14:09 +00:00
parent 93f93db555
commit a51c0bece1
2 changed files with 25 additions and 0 deletions

View File

@ -1,6 +1,7 @@
COMMENT= Motif toolkit
DISTNAME= motif-2.3.8
REVISION= 0
SHARED_LIBS += Xm 6.1 # 4.4
SHARED_LIBS += Mrm 4.1 # 4.4

View File

@ -0,0 +1,24 @@
Check bounds before accessing the keycaps table.
Index: lib/Xm/VirtKeys.c
--- lib/Xm/VirtKeys.c.orig
+++ lib/Xm/VirtKeys.c
@@ -558,10 +558,16 @@ FindVirtKey(Display *dpy,
XmDisplay xmDisplay = (XmDisplay) XmGetXmDisplay( dpy);
XmVKeyBinding keyBindings = xmDisplay->display.bindings;
KeyCode min_kcode;
- int ks_per_kc;
+ int min_kc, max_kc, ks_per_kc;
KeySym *ks_table = XtGetKeysymTable( dpy, &min_kcode, &ks_per_kc);
KeySym *kc_map = &ks_table[(keycode - min_kcode) * ks_per_kc];
- Modifiers EffectiveSMMask = EffectiveStdModMask( dpy, kc_map, ks_per_kc);
+ Modifiers EffectiveSMMask;
+
+ XDisplayKeycodes(dpy, &min_kc, &max_kc);
+ if (keycode < min_kcode || (keycode - min_kcode) * ks_per_kc >= max_kc)
+ return;
+
+ EffectiveSMMask = EffectiveStdModMask( dpy, kc_map, ks_per_kc);
/* Get the modifiers from the actual event */
Modifiers VirtualStdMods = 0;