mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Fix buffer overflow when file ends with \
This commit is contained in:
@@ -145,7 +145,7 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
|
|||||||
size = ftell(f);
|
size = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
|
|
||||||
pBuffer->pBufferRealStart = malloc(size + 2 + SAFETYMARGIN);
|
pBuffer->pBufferRealStart = malloc(size + 3 + SAFETYMARGIN);
|
||||||
|
|
||||||
if (pBuffer->pBufferRealStart == NULL)
|
if (pBuffer->pBufferRealStart == NULL)
|
||||||
fatalerror("%s: Out of memory for buffer!", __func__);
|
fatalerror("%s: Out of memory for buffer!", __func__);
|
||||||
@@ -156,8 +156,9 @@ YY_BUFFER_STATE yy_create_buffer(FILE *f)
|
|||||||
size = fread(pBuffer->pBuffer, sizeof(uint8_t), size, f);
|
size = fread(pBuffer->pBuffer, sizeof(uint8_t), size, f);
|
||||||
|
|
||||||
pBuffer->pBuffer[size] = '\n';
|
pBuffer->pBuffer[size] = '\n';
|
||||||
pBuffer->pBuffer[size + 1] = 0;
|
pBuffer->pBuffer[size + 1] = '\n'; /* in case the file ends with \ */
|
||||||
pBuffer->nBufferSize = size + 1;
|
pBuffer->pBuffer[size + 2] = 0;
|
||||||
|
pBuffer->nBufferSize = size + 2;
|
||||||
|
|
||||||
/* Convert all line endings to LF and spaces */
|
/* Convert all line endings to LF and spaces */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user