1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 23:29:39 +00:00

grc65 fix flawed text parsing

Was using fseek(F,-1,SEEK_CUR) which is invalid for text files, behaviour unreliable across platforms.
Added check for internal buffer overflow.
This commit is contained in:
bbbradsmith 2023-05-05 21:32:34 -04:00
parent a325c95652
commit 8d048699ee

View File

@ -850,8 +850,12 @@ static char *filterInput (FILE *F, char *tbl)
/* loads file into buffer filtering it out */
int a, prevchar = -1, i = 0, bracket = 0, quote = 1;
for (;;) {
a = getc(F);
a = getc(F);
while (1)
{
if (i >= BLOODY_BIG_BUFFER) {
AbEnd ("File too large for internal parsing buffer (%d bytes).",BLOODY_BIG_BUFFER);
}
if ((a == '\n') || (a == '\015')) a = ' ';
if (a == ',' && quote) a = ' ';
if (a == '\042') quote =! quote;
@ -873,13 +877,18 @@ static char *filterInput (FILE *F, char *tbl)
if (a == ';' && quote) {
do {
a = getc (F);
} while (a != '\n');
fseek (F, -1, SEEK_CUR);
} while (a != '\n' && a != EOF);
/* Don't discard this newline/EOF, continue to next loop.
** A previous implementation used fseek(F,-1,SEEK_CUR),
** which is invalid for text mode files, and was unreliable across platforms.
*/
continue;
} else {
tbl[i++] = a;
prevchar = a;
}
}
a = getc(F);
}
if (bracket != 0) AbEnd ("There are unclosed brackets!");