mirror of https://github.com/OpenTTD/OpenTTD
(svn r12165) -Fix [FS#1652, FS#1773]: buffer overflow when drawing scrolling news
parent
7394b9d030
commit
16e23a75fe
|
@ -1668,7 +1668,7 @@ static bool DrawScrollingStatusText(const NewsItem *ni, int pos, int width)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
StringID str;
|
StringID str;
|
||||||
const char *s;
|
const char *s, *last;
|
||||||
char *d;
|
char *d;
|
||||||
DrawPixelInfo tmp_dpi, *old_dpi;
|
DrawPixelInfo tmp_dpi, *old_dpi;
|
||||||
int x;
|
int x;
|
||||||
|
@ -1685,19 +1685,22 @@ static bool DrawScrollingStatusText(const NewsItem *ni, int pos, int width)
|
||||||
|
|
||||||
s = buf;
|
s = buf;
|
||||||
d = buffer;
|
d = buffer;
|
||||||
|
last = lastof(buffer);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
WChar c = Utf8Consume(&s);
|
WChar c = Utf8Consume(&s);
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
*d = '\0';
|
|
||||||
break;
|
break;
|
||||||
} else if (*s == 0x0D) {
|
} else if (c == 0x0D) {
|
||||||
|
if (d + 4 >= last) break;
|
||||||
d[0] = d[1] = d[2] = d[3] = ' ';
|
d[0] = d[1] = d[2] = d[3] = ' ';
|
||||||
d += 4;
|
d += 4;
|
||||||
} else if (IsPrintable(c)) {
|
} else if (IsPrintable(c)) {
|
||||||
|
if (d + Utf8CharLen(c) >= last) break;
|
||||||
d += Utf8Encode(d, c);
|
d += Utf8Encode(d, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*d = '\0';
|
||||||
|
|
||||||
if (!FillDrawPixelInfo(&tmp_dpi, 141, 1, width, 11)) return true;
|
if (!FillDrawPixelInfo(&tmp_dpi, 141, 1, width, 11)) return true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue