summaryrefslogtreecommitdiffstats
path: root/unix/tkUnixKey.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/tkUnixKey.c')
-rw-r--r--unix/tkUnixKey.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/unix/tkUnixKey.c b/unix/tkUnixKey.c
index 23c4aa4..dcdc85f 100644
--- a/unix/tkUnixKey.c
+++ b/unix/tkUnixKey.c
@@ -110,7 +110,7 @@ TkpGetString(
XEvent *eventPtr, /* X keyboard event. */
Tcl_DString *dsPtr) /* Initialized, empty string to hold result. */
{
- int len;
+ int len, mincode, maxcode;
Tcl_DString buf;
TkKeyEvent *kePtr = (TkKeyEvent *) eventPtr;
@@ -125,6 +125,32 @@ TkpGetString(
return Tcl_DStringValue(dsPtr);
}
+ /*
+ * Only do this for KeyPress events, otherwise
+ * further Xlib function behavior might be undefined.
+ */
+
+ if (eventPtr->type != KeyPress) {
+ len = 0;
+ Tcl_DStringSetLength(dsPtr, len);
+ goto done;
+ }
+
+ /*
+ * Filter keycodes out of range, otherwise
+ * further Xlib function behavior might be undefined.
+ */
+
+ mincode = 0;
+ maxcode = -1;
+ XDisplayKeycodes(winPtr->dispPtr->display, &mincode, &maxcode);
+ if ((eventPtr->xkey.keycode < mincode) ||
+ (eventPtr->xkey.keycode > maxcode)) {
+ len = 0;
+ Tcl_DStringSetLength(dsPtr, len);
+ goto done;
+ }
+
#ifdef TK_USE_INPUT_METHODS
if ((winPtr->dispPtr->flags & TK_DISPLAY_USE_IM)
&& (winPtr->inputContext != NULL)