mirror of
https://github.com/cc65/cc65.git
synced 2025-02-28 20:29:46 +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:
parent
a325c95652
commit
8d048699ee
@ -850,8 +850,12 @@ static char *filterInput (FILE *F, char *tbl)
|
|||||||
/* loads file into buffer filtering it out */
|
/* loads file into buffer filtering it out */
|
||||||
int a, prevchar = -1, i = 0, bracket = 0, quote = 1;
|
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 == '\n') || (a == '\015')) a = ' ';
|
||||||
if (a == ',' && quote) a = ' ';
|
if (a == ',' && quote) a = ' ';
|
||||||
if (a == '\042') quote =! quote;
|
if (a == '\042') quote =! quote;
|
||||||
@ -873,13 +877,18 @@ static char *filterInput (FILE *F, char *tbl)
|
|||||||
if (a == ';' && quote) {
|
if (a == ';' && quote) {
|
||||||
do {
|
do {
|
||||||
a = getc (F);
|
a = getc (F);
|
||||||
} while (a != '\n');
|
} while (a != '\n' && a != EOF);
|
||||||
fseek (F, -1, SEEK_CUR);
|
/* 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 {
|
} else {
|
||||||
tbl[i++] = a;
|
tbl[i++] = a;
|
||||||
prevchar = a;
|
prevchar = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
a = getc(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bracket != 0) AbEnd ("There are unclosed brackets!");
|
if (bracket != 0) AbEnd ("There are unclosed brackets!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user