Skip to content

Instantly share code, notes, and snippets.

@0xabad1dea

0xabad1dea/tricksy.c

Last active Dec 17, 2015
Embed
What would you like to do?
A deceitful C program
// 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

This comment has been minimized.

Copy link

@axiomsofchoice axiomsofchoice commented May 22, 2013

@0xabad1dea

This comment has been minimized.

Copy link
Owner Author

@0xabad1dea 0xabad1dea commented May 22, 2013

@axiomsofchoice Whoa spoiler alert :p

@SlaunchaMan

This comment has been minimized.

Copy link

@SlaunchaMan SlaunchaMan commented May 23, 2013

Whoa.

@oleganza

This comment has been minimized.

Copy link

@oleganza oleganza commented May 24, 2013

Nice.

@glug

This comment has been minimized.

Copy link

@glug glug commented May 24, 2013

Saw it immediately, ran into something similar before...

Note: Try to find the bug before compiling (gcc will output a warning).

@danmcd

This comment has been minimized.

Copy link

@danmcd danmcd commented Mar 17, 2014

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.

@iljavs

This comment has been minimized.

Copy link

@iljavs iljavs commented Mar 18, 2014

I've never actually seen trigraphs being used anywhere. interesting code sample none the less though.

@thethomaseffect

This comment has been minimized.

Copy link

@thethomaseffect thethomaseffect commented Mar 19, 2014

Cool, thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment