How not to prevent buffer overflows.
makomk last edited by
A while back, I encountered some... interesting code. Since the bug in question is long since fixed and the broken version is no longer in use anywhere, here it is (lightly anonymised and with some irrelevant error handling removed):
fscanf( file, "%[^\n]", buf );
MyString name = buf;
The coder obviously realised that the input could be longer than it should be, but didn't quite grasp the full implications. What's more, the code had allegedly just been audited for security holes. (In case you were wondering, yes, this could be exploited remotely for arbitrary code execution. It wasn't the only dubious fscanf, either, though most of them did actually have proper size limits set.)
Atrophy last edited by
LOL it's the coding equivalent of the "security" they've installed at our nation's airports the last few years...