Add range check for UI text buffer
It can't overflow because buff and text have the same max length (1024 and MAX_TOKENLENGTH).
This commit is contained in:
parent
797168fa08
commit
c8553223ec
|
|
@ -3001,6 +3001,7 @@ void Item_Text_Wrapped_Paint(itemDef_t *item) {
|
|||
char text[1024];
|
||||
const char *p, *start, *textPtr;
|
||||
char buff[1024];
|
||||
int length;
|
||||
int width, height;
|
||||
float x, y;
|
||||
vec4_t color;
|
||||
|
|
@ -3032,11 +3033,14 @@ void Item_Text_Wrapped_Paint(itemDef_t *item) {
|
|||
start = textPtr;
|
||||
p = strchr(textPtr, '\r');
|
||||
while (p && *p) {
|
||||
strncpy(buff, start, p-start+1);
|
||||
buff[p-start] = '\0';
|
||||
length = p-start+1;
|
||||
if (length > sizeof(buff)) {
|
||||
length = sizeof(buff);
|
||||
}
|
||||
Q_strncpyz(buff, start, length);
|
||||
DC->drawText(x, y, item->textscale, color, buff, 0, 0, item->textStyle);
|
||||
y += height + 5;
|
||||
start += p - start + 1;
|
||||
start += length;
|
||||
p = strchr(p+1, '\r');
|
||||
}
|
||||
DC->drawText(x, y, item->textscale, color, start, 0, 0, item->textStyle);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user