Browse Source

TextSubtext fixes (#4759)

Fix buffer write overflow
Fix reading past the end of text
pull/4763/head
veins1 1 week ago
committed by GitHub
parent
commit
1d87932d93
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 6 deletions
  1. +6
    -6
      src/rtext.c

+ 6
- 6
src/rtext.c View File

@ -1540,21 +1540,21 @@ const char *TextSubtext(const char *text, int position, int length)
if (position >= textLength)
{
position = textLength - 1;
length = 0;
return buffer; //First char is already '\0' by memset
}
if (length >= textLength) length = textLength;
int maxLength = textLength - position;
if (length > maxLength) length = maxLength;
if (length >= MAX_TEXT_BUFFER_LENGTH) length = MAX_TEXT_BUFFER_LENGTH - 1;
// NOTE: Alternative: memcpy(buffer, text + position, length)
for (int c = 0 ; c < length ; c++)
{
*(buffer + c) = *(text + position);
text++;
buffer[c] = text[position + c];
}
o">*(buffer + length) = '\0';
n">buffer[length] = '\0';
return buffer;
}

Loading…
Cancel
Save