Last active
December 17, 2015 14:59
-
-
Save 0xabad1dea/5628766 to your computer and use it in GitHub Desktop.
A deceitful C program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// hello clever programmers, would you like to play a game? | |
// where's the bug? | |
// by 0xabad1dea :) | |
#include <stdio.h> | |
#include <string.h> | |
int main() { | |
char input[16] = "stringstring!!!"; | |
char output[8]; | |
//so this will leave it not terminated// | |
strncpy(output, input, 8); | |
//but this will fix it right??/ | |
output[7] = '\0'; | |
//so what happens here?// | |
printf("%s\n", output); | |
return 0; | |
} | |
// HINT: the behavior of this program depends on whether your | |
// compiler has turned ON or OFF a certain genuine ANSI C feature! | |
// also, modern stack protectors will keep this from being | |
// usefully exploitable, but that's besides the point |
@axiomsofchoice Whoa spoiler alert :p
Whoa.
Nice.
Saw it immediately, ran into something similar before...
Note: Try to find the bug before compiling (gcc will output a warning).
Fercryinoutloud. I'm having flashbacks to C/400 for the AS/400. My introduction to trigraphs, and the only time I found more bugs in the compiler than the code I was testing.
I've never actually seen trigraphs being used anywhere. interesting code sample none the less though.
Cool, thanks for this!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://flash-gordon.me.uk/ansi.c.txt section 2.2.1.1