From a51c0bece15d65982da2955459cd6fcd0fdce36a Mon Sep 17 00:00:00 2001 From: tb Date: Mon, 7 Nov 2022 18:14:09 +0000 Subject: [PATCH] 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 --- x11/motif/Makefile | 1 + x11/motif/patches/patch-lib_Xm_VirtKeys_c | 24 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 x11/motif/patches/patch-lib_Xm_VirtKeys_c diff --git a/x11/motif/Makefile b/x11/motif/Makefile index 40b23a1af0a..8d7ad1c88ab 100644 --- a/x11/motif/Makefile +++ b/x11/motif/Makefile @@ -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 diff --git a/x11/motif/patches/patch-lib_Xm_VirtKeys_c b/x11/motif/patches/patch-lib_Xm_VirtKeys_c new file mode 100644 index 00000000000..cdd9d2ee95c --- /dev/null +++ b/x11/motif/patches/patch-lib_Xm_VirtKeys_c @@ -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;