libsodium: updated to 1.0.10
[tomato.git] / release / src / router / libsodium / test / default / sodium_utils3.c
blob603cf757d38040965eb57458e27e9edddf927b99
2 #include <stdlib.h>
3 #include <sys/types.h>
5 #include <limits.h>
6 #include <signal.h>
8 #define TEST_NAME "sodium_utils3"
9 #include "cmptest.h"
11 #ifdef __SANITIZE_ADDRESS__
12 # warning The sodium_utils3 test is expected to fail with address sanitizer
13 #endif
15 __attribute__ ((noreturn)) static void segv_handler(int sig)
17 (void) sig;
19 printf("Intentional segfault / bus error caught\n");
20 printf("OK\n");
21 #ifdef SIGSEGV
22 signal(SIGSEGV, SIG_DFL);
23 #endif
24 #ifdef SIGBUS
25 signal(SIGBUS, SIG_DFL);
26 #endif
27 #ifdef SIGABRT
28 signal(SIGABRT, SIG_DFL);
29 #endif
30 exit(0);
33 int main(void)
35 void *buf;
36 size_t size;
38 #ifdef SIGSEGV
39 signal(SIGSEGV, segv_handler);
40 #endif
41 #ifdef SIGBUS
42 signal(SIGBUS, segv_handler);
43 #endif
44 #ifdef SIGABRT
45 signal(SIGABRT, segv_handler);
46 #endif
47 size = 1U + randombytes_uniform(100000U);
48 buf = sodium_malloc(size);
49 assert(buf != NULL);
50 sodium_mprotect_noaccess(buf);
51 sodium_mprotect_readwrite(buf);
52 #ifndef __EMSCRIPTEN__
53 sodium_memzero(((unsigned char *)buf) - 8, 8U);
54 sodium_mprotect_readonly(buf);
55 sodium_free(buf);
56 printf("Underflow not caught\n");
57 #endif
58 return 0;