-
-
Save anonymous/a7dd93829526bd9e78ef to your computer and use it in GitHub Desktop.
Simple use of a canary
This file contains 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
#include <stdio.h> | |
#include "lib.h" | |
#define CANARY_VALUE 0x42424242 | |
int main(void) | |
{ | |
int lib_data[LIB_DATA_SIZE+1]; /* Allocating lib data plus one element (the canary) */ | |
int *canary = &lib_data[LIB_DATA_SIZE]; /* the canary is just after the lib_data */ | |
*canary = CANARY_VALUE; /* Setting the canary */ | |
calling_the_lib(lib_data); /* Calling the somewhat "shady" lib */ | |
if(*canary != CANARY_VALUE) /* Testing the canary */ | |
printf("Poor Canary died and lib did a buffer overflow\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment