| 5 | typedef int (*PFOO)(void); |
| 6 | |
| 7 | int main(int ac, char **av) |
| 8 | { |
| 9 | printf("start\n"); |
| 10 | |
| 11 | if(!strcmp(av[1], "segfault")) { |
| 12 | printf("accessing from 0xDEADBEEF\n"); |
| 13 | return *(int *)0xDEADBEEF; |
| 14 | } |
| 15 | |
| 16 | if(!strcmp(av[1], "illegalinstr")) { |
| 17 | #if defined(ARCH_IS_X64) |
| 18 | printf("X64 bad instruction\n"); |
| 19 | unsigned char buf[] = { |
| 20 | 0x66, 0x06, // push es on x86, invalid in x64 |
| 21 | 0x0f, 0xb9, // ud2b |
| 22 | 0x0f, 0x0b, // ud2 |
| 23 | 0xfe, 0xf0, |
| 24 | 0x90, |
| 25 | 0x90 |
| 26 | #elif defined(ARCH_IS_X86) |
| 27 | printf("X86 bad instruction\n"); |
| 28 | unsigned char buf[] = { |
| 29 | 0x0f, 0x0b // ud2 |
| 30 | #elif defined(ARCH_IS_ARMV7) |
| 31 | printf("ARMV7 bad instruction\n"); |
| 32 | unsigned char buf[] = { |
| 33 | 0xf0, 0xde, 0xf0, 0xe7, // little endian 0xe7f0def0 |
| 34 | 0xe7, 0xf0, 0xde, 0xf0 // big endian |
| 35 | #elif defined(ARCH_IS_AARCH64) |
| 36 | printf("AARCH64 bad instruction\n"); |
| 37 | unsigned char buf[] = { |
| 38 | // https://developer.arm.com/docs/ddi0596/a/a64-base-instructions-alphabetic-order/udf-permanently-undefined |
| 39 | 0x00, 0x00, 0x00, 0x00 |
| 40 | #endif |
| 41 | }; |
| 42 | |
| 43 | PFOO bar = (PFOO)buf; |
| 44 | return bar(); |
| 45 | } |
| 46 | |
| 47 | if(!strcmp(av[1], "divzero")) { |
| 48 | printf("dividing by zero\n"); |
| 49 | int foo = 31337; |
| 50 | float result = 0; |
| 51 | int i = 9; |
| 52 | while(i >= 0) { |
| 53 | printf("dividing by %d\n", i); |
| 54 | result = foo/i; |
| 55 | i -= 1; |
| 56 | printf("result is: %f\n", result); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | printf("end\n"); |
| 61 | return 0; |
| 62 | } |
nothing calls this directly
no outgoing calls
no test coverage detected