Avoid excessive stack allocations, particularly in situations where the growth of the stack can be controlled of or influenced by an attacker.
...
Code Block | ||
---|---|---|
| ||
int copy_file(FILE *src, FILE *dst, size_t bufsize) {
char *buf = malloc(bufsize);
if (!buf) {
return -1;
}
while (fgets(buf, bufsize, src)) {
fputs(buf, dst);
}
free(buf);
buf = NULL;
return 0;
}
|
Non-Compliant Code Example
...