[parser] Don't crash for files that don't end in newlines (#3981)

The parser assumes all lines end in newlines, but sometimes this isn't
true. Check for a null terminator along with '\n' when stripping leading
spaces.
This commit is contained in:
Peter0x44 2024-05-15 07:16:45 -07:00 committed by GitHub
parent 3d885ef919
commit bf5eecc71f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 1 deletions

View File

@ -1243,7 +1243,7 @@ static char **GetTextLines(const char *buffer, int length, int *linesCount)
while ((bufferPtr[index] == ' ') || (bufferPtr[index] == '\t')) index++;
int j = 0;
while (bufferPtr[index + j] != '\n')
while (bufferPtr[index + j] != '\n' && bufferPtr[index + j] != '\0')
{
lines[i][j] = bufferPtr[index + j];
j++;