The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/libsodium/test/default/sodium_utils3.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 
    2 #include <stdlib.h>
    3 #include <sys/types.h>
    4 
    5 #include <limits.h>
    6 #include <signal.h>
    7 
    8 #define TEST_NAME "sodium_utils3"
    9 #include "cmptest.h"
   10 
   11 #ifdef __SANITIZE_ADDRESS__
   12 # warning The sodium_utils3 test is expected to fail with address sanitizer
   13 #endif
   14 
   15 __attribute__((noreturn)) static void
   16 segv_handler(int sig)
   17 {
   18     (void) sig;
   19 
   20     printf("Intentional segfault / bus error caught\n");
   21     printf("OK\n");
   22 #ifdef SIGSEGV
   23     signal(SIGSEGV, SIG_DFL);
   24 #endif
   25 #ifdef SIGBUS
   26     signal(SIGBUS, SIG_DFL);
   27 #endif
   28 #ifdef SIGABRT
   29     signal(SIGABRT, SIG_DFL);
   30 #endif
   31     exit(0);
   32 }
   33 
   34 int
   35 main(void)
   36 {
   37     void * buf;
   38     size_t size;
   39 
   40 #ifdef SIGSEGV
   41     signal(SIGSEGV, segv_handler);
   42 #endif
   43 #ifdef SIGBUS
   44     signal(SIGBUS, segv_handler);
   45 #endif
   46 #ifdef SIGABRT
   47     signal(SIGABRT, segv_handler);
   48 #endif
   49     size = 1U + randombytes_uniform(100000U);
   50     buf  = sodium_malloc(size);
   51     assert(buf != NULL);
   52 
   53 /* old versions of asan emit a warning because they don't support mlock*() */
   54 #ifndef __SANITIZE_ADDRESS__
   55     sodium_mprotect_noaccess(buf);
   56     sodium_mprotect_readwrite(buf);
   57 #endif
   58 
   59 #if defined(HAVE_CATCHABLE_SEGV) && !defined(__EMSCRIPTEN__) && !defined(__SANITIZE_ADDRESS__)
   60     sodium_memzero(((unsigned char *) buf) - 8, 8U);
   61     sodium_mprotect_readonly(buf);
   62     sodium_free(buf);
   63     printf("Underflow not caught\n");
   64 #else
   65     segv_handler(0);
   66 #endif
   67     return 0;
   68 }

Cache object: dcd75173a28a3a52fd4f171fa2e4783c


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.