diff options
author | fvogel <fvogelnew1@free.fr> | 2018-01-16 19:48:05 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2018-01-16 19:48:05 (GMT) |
commit | d2940e0fe1da5d48bc498b29dde3054b400d784c (patch) | |
tree | 8b5dd5cbb8256acee733098fc1d12e9e63df9b77 | |
parent | d24d7ec4f6d82f6b6ef49d019190a9abfefc6f7c (diff) | |
parent | f31bbfba24cd33c7a6421f69e1760bd54bdaba4f (diff) | |
download | tk-d2940e0fe1da5d48bc498b29dde3054b400d784c.zip tk-d2940e0fe1da5d48bc498b29dde3054b400d784c.tar.gz tk-d2940e0fe1da5d48bc498b29dde3054b400d784c.tar.bz2 |
Fix [382712ade6]: X11: 'event generate . <KeyPress>' segfaults. Patch from Christian Werner.
-rw-r--r-- | unix/tkUnixKey.c | 28 |
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) |