Commit ebc5fe96 authored by Ulrich Czekalla's avatar Ulrich Czekalla Committed by Alexandre Julliard

Prevent buffer overflow in TEXT_NextLineW.

parent 9086d42d
...@@ -49,7 +49,7 @@ static int prefix_offset; ...@@ -49,7 +49,7 @@ static int prefix_offset;
* str - string to parse into lines. * str - string to parse into lines.
* count - length of str. * count - length of str.
* dest - destination in which to return line. * dest - destination in which to return line.
* len - length of resultant line in dest in chars. * len - dest buffer size in chars on input, copied length into dest on output.
* width - maximum width of line in pixels. * width - maximum width of line in pixels.
* format - format type passed to DrawText. * format - format type passed to DrawText.
* *
...@@ -70,8 +70,9 @@ static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count, ...@@ -70,8 +70,9 @@ static const WCHAR *TEXT_NextLineW( HDC hdc, const WCHAR *str, int *count,
SIZE size; SIZE size;
int lasttab = 0; int lasttab = 0;
int wb_i = 0, wb_j = 0, wb_count = 0; int wb_i = 0, wb_j = 0, wb_count = 0;
int maxl = *len;
while (*count) while (*count && j < maxl)
{ {
switch (str[i]) switch (str[i])
{ {
...@@ -223,12 +224,13 @@ INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT ...@@ -223,12 +224,13 @@ INT16 WINAPI DrawText16( HDC16 hdc, LPCSTR str, INT16 count, LPRECT16 rect, UINT
/*********************************************************************** /***********************************************************************
* DrawTextExW (USER32.166) * DrawTextExW (USER32.166)
*/ */
#define MAX_STATIC_BUFFER 1024
INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT i_count, INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT i_count,
LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp ) LPRECT rect, UINT flags, LPDRAWTEXTPARAMS dtp )
{ {
SIZE size; SIZE size;
const WCHAR *strPtr; const WCHAR *strPtr;
static WCHAR line[1024]; static WCHAR line[MAX_STATIC_BUFFER];
int len, lh, count=i_count; int len, lh, count=i_count;
int prefix_x = 0; int prefix_x = 0;
int prefix_end = 0; int prefix_end = 0;
...@@ -272,6 +274,7 @@ INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT i_count, ...@@ -272,6 +274,7 @@ INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT i_count,
do do
{ {
prefix_offset = -1; prefix_offset = -1;
len = MAX_STATIC_BUFFER;
strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags); strPtr = TEXT_NextLineW(hdc, strPtr, &count, line, &len, width, flags);
if (prefix_offset != -1) if (prefix_offset != -1)
...@@ -339,6 +342,7 @@ INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT i_count, ...@@ -339,6 +342,7 @@ INT WINAPI DrawTextExW( HDC hdc, LPCWSTR str, INT i_count,
strncpyW(swapStr+strlenW(swapStr), str, totalLen); strncpyW(swapStr+strlenW(swapStr), str, totalLen);
} }
len = MAX_STATIC_BUFFER;
TEXT_NextLineW(hdc, swapStr, &count, line, &len, width, flags); TEXT_NextLineW(hdc, swapStr, &count, line, &len, width, flags);
/* if only the ELLIPSIS will fit, just let it be clipped */ /* if only the ELLIPSIS will fit, just let it be clipped */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment