From 3d906db0a5542a0d5d4cddf2833075861f6b001e Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Tue, 21 Mar 2017 21:42:32 +0100 Subject: Fix overflow case returned by XmbLookupString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit man of XbmLookupString when XBufferOverflow: XBufferOverflow The input string to be returned is too large for the supplied buffer_return. The required size (for XmbLookupString, Xutf8LookupString in bytes; for XwcLookup‐ String in characters) is returned as the value of the function, and the contents of buffer_return and keysym_return are not modified. The client should recall the function with the same event and a buffer of adequate size to obtain the string. So in this case retrieve length expected then call it with +1 for null termination Change-Id: I8507bb249a411c7e899746e0598f4a055a26fb19 Reviewed-on: https://gerrit.libreoffice.org/35519 Tested-by: Jenkins Reviewed-by: Michael Stahl --- vcl/unx/generic/window/salframe.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'vcl') diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx index 3183c0b67167..af37168137bb 100644 --- a/vcl/unx/generic/window/salframe.cxx +++ b/vcl/unx/generic/window/salframe.cxx @@ -3009,7 +3009,10 @@ long X11SalFrame::HandleKeyEvent( XKeyEvent *pEvent ) &nStatus, mpInputContext->GetContext() ); if ( nStatus == XBufferOverflow ) { - nLen *= 2; + // In case of overflow, XmbLookupString (called by GetKeySym) + // returns required size + // TODO : check if +1 is needed for 0 terminator + nLen += 1; pPrintable = static_cast(alloca( nLen )); nKeySym = pDisplay_->GetKeySym( pEvent, pPrintable, &nLen, &nUnmodifiedKeySym, -- cgit