32 lines · cpp
1#include <cstdlib>2#include <cstring>3#include <iostream>4 5namespace {6const char *const SEGFAULT_COMMAND = "segfault";7const char *const ABORT_COMMAND = "abort";8}9 10int main(int argc, char **argv) {11 if (argc < 2) {12 std::cout << "expected at least one command provided on the command line"13 << std::endl;14 }15 16 // Process command line args.17 for (int i = 1; i < argc; ++i) {18 const char *const command = argv[i];19 if (std::strstr(command, SEGFAULT_COMMAND)) {20 // Perform a null pointer access.21 int *const null_int_ptr = nullptr;22 *null_int_ptr = 0xDEAD;23 } else if (std::strstr(command, ABORT_COMMAND)) {24 std::abort();25 } else {26 std::cout << "Unsupported command: " << command << std::endl;27 }28 }29 30 return 0;31}32