You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1022 B

  1. #include <sys/types.h>
  2. #include <limits.h>
  3. #include <signal.h>
  4. #define TEST_NAME "sodium_utils3"
  5. #include "cmptest.h"
  6. #ifdef __SANITIZE_ADDRESS__
  7. # error This test requires address sanitizer to be off
  8. #endif
  9. static void segv_handler(int sig)
  10. {
  11. printf("Intentional segfault / bus error caught\n");
  12. printf("OK\n");
  13. #ifdef SIGSEGV
  14. signal(SIGSEGV, SIG_DFL);
  15. #endif
  16. #ifdef SIGBUS
  17. signal(SIGBUS, SIG_DFL);
  18. #endif
  19. #ifdef SIGABRT
  20. signal(SIGABRT, SIG_DFL);
  21. #endif
  22. exit(0);
  23. }
  24. int main(void)
  25. {
  26. void *buf;
  27. size_t size;
  28. #ifdef SIGSEGV
  29. signal(SIGSEGV, segv_handler);
  30. #endif
  31. #ifdef SIGBUS
  32. signal(SIGBUS, segv_handler);
  33. #endif
  34. #ifdef SIGABRT
  35. signal(SIGABRT, segv_handler);
  36. #endif
  37. size = randombytes_uniform(100000U);
  38. buf = sodium_malloc(size);
  39. sodium_mprotect_noaccess(buf);
  40. sodium_mprotect_readwrite(buf);
  41. sodium_memzero(((unsigned char *)buf) - 8, 8U);
  42. sodium_mprotect_readonly(buf);
  43. sodium_free(buf);
  44. printf("Underflow not caught\n");
  45. return 0;
  46. }