From 44cd974fffc3e890ac363ebaf6ccf5693c7daa9b Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Fri, 16 Nov 2001 18:14:17 +0000
Subject: [PATCH] Truncate the window text if it is too large for the request
 buffer.

---
 windows/defwnd.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/windows/defwnd.c b/windows/defwnd.c
index b12c75681af..d56404c8c7d 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -75,13 +75,15 @@ static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
     if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
     if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
     {
+        size_t len = min( REQUEST_MAX_VAR_SIZE, (count-1) * sizeof(WCHAR) );
+
         if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
         wndPtr->text = textW;
         MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
-        SERVER_START_VAR_REQ( set_window_text, (count-1) * sizeof(WCHAR) )
+        SERVER_START_VAR_REQ( set_window_text, len )
         {
             req->handle = hwnd;
-            memcpy( server_data_ptr(req), textW, (count-1) * sizeof(WCHAR) );
+            memcpy( server_data_ptr(req), textW, len );
             SERVER_CALL();
         }
         SERVER_END_VAR_REQ;
@@ -111,11 +113,13 @@ static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
     if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
     if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
     {
+        size_t len = min( REQUEST_MAX_VAR_SIZE, (count-1) * sizeof(WCHAR) );
+
         strcpyW( wndPtr->text, text );
-        SERVER_START_VAR_REQ( set_window_text, (count-1) * sizeof(WCHAR) )
+        SERVER_START_VAR_REQ( set_window_text, len )
         {
             req->handle = hwnd;
-            memcpy( server_data_ptr(req), wndPtr->text, (count-1) * sizeof(WCHAR) );
+            memcpy( server_data_ptr(req), wndPtr->text, len );
             SERVER_CALL();
         }
         SERVER_END_VAR_REQ;
-- 
GitLab