Skip to content

Instantly share code, notes, and snippets.

/canary.c Secret

Created June 4, 2013 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a7dd93829526bd9e78ef to your computer and use it in GitHub Desktop.
Save anonymous/a7dd93829526bd9e78ef to your computer and use it in GitHub Desktop.
Simple use of a canary
#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