Below is our example code.
strsep example
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
char *s = strdup("This is a test");
char *deleteme = s;
char *d = " ";
while(s) {
char *token = strsep(&s, d);
puts(token);
}
free(deleteme);
return 0;
}
buffer overflow
#include <string.h>
#include <stdio.h>
int main() {
char buffer[100];
//const char *s1 = "This is a test";
//const char *s2 = " of string.h";
const char *s1 = "This is a test AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
const char *s2 = " of string.h AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
buffer[0] = '\0';
strcat(buffer, s1);
strcat(buffer, s2);
puts(buffer);
return 0;
}
To include the stack canary, compile with clang -fstack-protector
.