Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1/* an example that should be protected by FORTIFY_SOURCE=1 */ 2#include <stdio.h> 3#include <string.h> 4#include <stdlib.h> 5 6 7int main(int argc, char *argv[]) { 8 /* allocate on the heap so we're likely to get an 9 * over-allocation and can be more sure that a 10 * failure is because of fortify protection rather 11 * than a genuine segfault */ 12 char* buffer = malloc(sizeof(char) * 7); 13 strcpy(buffer, argv[1]); 14 puts(buffer); 15 return 0; 16}