···11+/* an example that should be protected by FORTIFY_SOURCE=1 */
22+#include <stdio.h>
33+#include <string.h>
44+#include <stdlib.h>
55+66+77+int main(int argc, char *argv[]) {
88+ /* allocate on the heap so we're likely to get an
99+ * over-allocation and can be more sure that a
1010+ * failure is because of fortify protection rather
1111+ * than a genuine segfault */
1212+ char* buffer = malloc(sizeof(char) * 7);
1313+ strcpy(buffer, argv[1]);
1414+ puts(buffer);
1515+ return 0;
1616+}
+16
pkgs/test/cc-wrapper/fortify2-example.c
···11+/* an example that should be protected by FORTIFY_SOURCE=2 but
22+ * not FORTIFY_SOURCE=1 */
33+#include <stdio.h>
44+#include <string.h>
55+66+struct buffer_with_pad {
77+ char buffer[7];
88+ char pad[25];
99+};
1010+1111+int main(int argc, char *argv[]) {
1212+ struct buffer_with_pad b;
1313+ strcpy(b.buffer, argv[1]);
1414+ puts(b.buffer);
1515+ return 0;
1616+}
+13
pkgs/test/cc-wrapper/fortify3-example.c
···11+/* an example that should be protected by FORTIFY_SOURCE=3 but
22+ * not FORTIFY_SOURCE=2 */
33+#include <stdio.h>
44+#include <string.h>
55+#include <stdlib.h>
66+77+88+int main(int argc, char *argv[]) {
99+ char* buffer = malloc(atoi(argv[2]));
1010+ strcpy(buffer, argv[1]);
1111+ puts(buffer);
1212+ return 0;
1313+}