f = fopen("filename", "r");
c = fgetc(f);
if(c < 0) {
fclose(f);
system("type filename > filename.tmp");
f = fopen("filename.tmp", "r");
}
else {
rewind(f);
}
while(fgets(buff, 256, f) != NULL)
puts(f);
fclose(f);
return(0);
}
Name:
Anonymous2012-01-12 21:46
No buffer overflow prevention, therefore highly exploitable. What if ``filename'' was malicious machine code and you overflowed the buffer, causing malicious machine code to spill into the saved call point in memory, causing the code to run when the function returned? You're screwed.