Avoid buffer overflow in _XimLookupMBText & _XimLookupUTF8Text

Reported-by: u32i <u32i@proton.me>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/lib/libx11/-/merge_requests/251>
This commit is contained in:
Alan Coopersmith 2024-05-18 11:41:36 -07:00 committed by Marge Bot
parent 0af3328dc3
commit c099d0105f

View file

@ -177,6 +177,8 @@ _XimLookupMBText(
if ((nbytes == 0) || (symbol == NoSymbol)) return count;
if (count > 1) {
if ((unsigned)count >= sizeof(look))
return 0;
memcpy(look, (char *)buffer,count);
look[count] = '\0';
if ((count = im->methods->ctstombs(ic->core.im,
@ -320,6 +322,8 @@ _XimLookupUTF8Text(
if ((nbytes == 0) || (symbol == NoSymbol)) return count;
if (count > 1) {
if ((unsigned)count >= sizeof(look))
return 0;
memcpy(look, (char *)buffer,count);
look[count] = '\0';
if ((count = im->methods->ctstoutf8(ic->core.im,