···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+7+int 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+}
+16
pkgs/test/cc-wrapper/fortify2-example.c
···0000000000000000
···1+/* an example that should be protected by FORTIFY_SOURCE=2 but
2+ * not FORTIFY_SOURCE=1 */
3+#include <stdio.h>
4+#include <string.h>
5+6+struct buffer_with_pad {
7+ char buffer[7];
8+ char pad[25];
9+};
10+11+int main(int argc, char *argv[]) {
12+ struct buffer_with_pad b;
13+ strcpy(b.buffer, argv[1]);
14+ puts(b.buffer);
15+ return 0;
16+}
+13
pkgs/test/cc-wrapper/fortify3-example.c
···0000000000000
···1+/* an example that should be protected by FORTIFY_SOURCE=3 but
2+ * not FORTIFY_SOURCE=2 */
3+#include <stdio.h>
4+#include <string.h>
5+#include <stdlib.h>
6+7+8+int main(int argc, char *argv[]) {
9+ char* buffer = malloc(atoi(argv[2]));
10+ strcpy(buffer, argv[1]);
11+ puts(buffer);
12+ return 0;
13+}