libsodium update to 0.7.0
[tomato.git] / release / src / router / libsodium / test / default / sodium_utils3.c
blobd9f1ab68973446737555705132c08716e6cb5497
2 #include <sys/types.h>
4 #include <limits.h>
5 #include <signal.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <string.h>
10 #define TEST_NAME "sodium_utils3"
11 #include "cmptest.h"
13 static void
14 segv_handler(int sig)
16 printf("Intentional segfault / bus error caught\n");
17 printf("OK\n");
18 #ifdef SIGSEGV
19 signal(SIGSEGV, SIG_DFL);
20 #endif
21 #ifdef SIGBUS
22 signal(SIGBUS, SIG_DFL);
23 #endif
24 #ifdef SIGABRT
25 signal(SIGABRT, SIG_DFL);
26 #endif
27 exit(0);
30 int
31 main(void)
33 void *buf;
34 size_t size;
36 #ifdef SIGSEGV
37 signal(SIGSEGV, segv_handler);
38 #endif
39 #ifdef SIGBUS
40 signal(SIGBUS, segv_handler);
41 #endif
42 #ifdef SIGABRT
43 signal(SIGABRT, segv_handler);
44 #endif
45 size = randombytes_uniform(100000U);
46 buf = sodium_malloc(size);
47 sodium_mprotect_noaccess(buf);
48 sodium_mprotect_readwrite(buf);
49 sodium_memzero(((unsigned char *) buf) - 8, 8U);
50 sodium_mprotect_readonly(buf);
51 sodium_free(buf);
52 printf("Underflow not caught\n");
54 return 0;