Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp buffer overflow on long lines #24

Open
drh opened this issue Jul 25, 2015 · 1 comment
Open

cpp buffer overflow on long lines #24

drh opened this issue Jul 25, 2015 · 1 comment

Comments

@drh
Copy link
Owner

drh commented Jul 25, 2015

---------- Forwarded message ---------
From: nikonsmith [email protected]
Date: Mon, Jul 20, 2015 at 10:49 PM
Subject: lcc's cpp bug
To: [email protected] [email protected]

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 <stdio.h>

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
Copy link

rofl0r commented Jul 25, 2015

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants