drh / lcc

The lcc retargetable ANSI C compiler
https://drh.github.io/lcc/
2.03k stars 441 forks source link

cpp buffer overflow on long lines #24

Open drh opened 9 years ago

drh commented 9 years ago

---------- Forwarded message --------- From: nikonsmith tonekit@hotmail.com Date: Mon, Jul 20, 2015 at 10:49 PM Subject: lcc's cpp bug To: drh@drhanson.net drh@drhanson.net

cpp bug:

when I compile a c source file which have a line that much than 32KB, it then print `Input buffer overflow' and exit process.

for example, I write a program generate a c source file that 100KB in one line,as follow:

/* generate.c */

include

int code_len = 100*1024; // 100KB c source code

int main(void) { char *str="int a%04d=10;"; int str_len = 13; int str_nr = code_len / str_len; int i; for(i=0;i<str_nr;i++) { printf(str,i); } printf("\nint main(void) { return 0; }\n"); return 0; }

$ ./generate > 100k.c

$ lcc -v 100k.c cpp: 100k.c:1 Input buffer overflow

rofl0r commented 9 years ago

according to posix: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html

<limits.h>
{LINE_MAX}
    Unless otherwise noted, the maximum length, in bytes, of a utility's input line (either standard input or another file), when the utility is described as processing text files. The length includes room for the trailing <newline>.
    Minimum Acceptable Value: {_POSIX2_LINE_MAX}

so a C file with 100KB line length is not a valid textfile (LINE_MAX is typically 4KB).