void tests_rand_start (void) { gmp_randstate_ptr rands; char *seed_string; if (__gmp_rands_initialized) { printf ("Please let tests_start() initialize the global __gmp_rands.\n"); printf ("ie. ensure that function is called before the first use of RANDS.\n"); abort (); } gmp_randinit_default (__gmp_rands); __gmp_rands_initialized = 1; rands = __gmp_rands; seed_string = getenv ("GMP_CHECK_RANDOMIZE"); if (seed_string != NULL) { if (strcmp (seed_string, "0") != 0 && strcmp (seed_string, "1") != 0) { mpz_t seed; mpz_init_set_str (seed, seed_string, 0); gmp_printf ("Re-seeding with GMP_CHECK_RANDOMIZE=%Zd\n", seed); gmp_randseed (rands, seed); mpz_clear (seed); } else { FILE *fs = fopen ("/dev/urandom", "r"); if (fs != NULL) { seed_from_urandom (rands, fs); fclose (fs); } else seed_from_tod (rands); } fflush (stdout); } }
int main(int argc, char* argv[]) { int ret; unsigned int i; printf("Trinity v" __stringify(VERSION) " Dave Jones <*****@*****.**> 2012\n"); #ifdef __x86_64__ syscalls = syscalls_x86_64; max_nr_syscalls = NR_X86_64_SYSCALLS; #elif __i386__ syscalls = syscalls_i386; max_nr_syscalls = NR_I386_SYSCALLS; #elif __powerpc__ syscalls = syscalls_ppc; #elif __ia64__ syscalls = syscalls_ia64; #elif __sparc__ syscalls = syscalls_sparc; #else syscalls = syscalls_i386; #endif progname = argv[0]; parse_args(argc, argv); if (getuid() == 0) { if (dangerous == 1) { printf("DANGER: RUNNING AS ROOT.\n"); printf("Unless you are running in a virtual machine, this could cause serious problems such as overwriting CMOS\n"); printf("or similar which could potentially make this machine unbootable without a firmware reset.\n\n"); printf("ctrl-c now unless you really know what you are doing.\n"); for (i = 10; i > 0; i--) { printf("Continuing in %d seconds.\r", i); (void)fflush(stdout); sleep(1); } } else { printf("Don't run as root (or pass --dangerous if you know what you are doing).\n"); exit(EXIT_FAILURE); } } if (create_shm()) exit(EXIT_FAILURE); if (logging != 0) open_logfiles(); max_nr_syscalls = NR_SYSCALLS; for (i = 0; i < max_nr_syscalls; i++) syscalls[i].entry->number = i; if (desired_group == GROUP_VM) { struct syscalltable *newsyscalls; int count = 0, j = 0; for (i = 0; i < max_nr_syscalls; i++) { if (syscalls[i].entry->group == GROUP_VM) count++; } newsyscalls = malloc(count * sizeof(struct syscalltable)); if (newsyscalls == NULL) exit(EXIT_FAILURE); for (i = 0; i < max_nr_syscalls; i++) { if (syscalls[i].entry->group == GROUP_VM) newsyscalls[j++].entry = syscalls[i].entry; } max_nr_syscalls = count; syscalls = newsyscalls; } if (!do_specific_syscall) output("Fuzzing %d syscalls.\n", max_nr_syscalls); if (do_specific_syscall == 1) find_specific_syscall(); if (do_specific_proto == 1) find_specific_proto(); if (show_syscall_list == 1) { syscall_list(); exit(EXIT_SUCCESS); } page_size = getpagesize(); if (!seed) seed_from_tod(); else output("[%d] Random seed: %u (0x%x)\n", getpid(), seed, seed); init_buffers(); mask_signals(); setup_fds(); if (check_tainted() != 0) { output("Kernel was tainted on startup. Will keep running if trinity causes an oops.\n"); do_check_tainted = 1; } /* just in case we're not using the test.sh harness. */ chmod("tmp/", 0755); ret = chdir("tmp/"); if (!ret) { /* nothing right now */ } main_loop(); printf("\nRan %ld syscalls (%ld retries). Successes: %ld Failures: %ld\n", shm->execcount - 1, shm->retries, shm->successes, shm->failures); shmdt(shm); destroy_maps(); for (i = 0; i < socks; i++) close(socket_fds[i]); if (logging != 0) close_logfiles(); exit(EXIT_SUCCESS); }