diff options
author | Mike Frysinger <vapier@gentoo.org> | 2008-11-16 16:13:01 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2008-11-16 16:13:01 +0000 |
commit | 31599d72d7bdb0cccef5d446d3761759bd06f6bb (patch) | |
tree | cf5ecfdf1de547d4e63ccfc160b83baade9211ea | |
parent | tests: execute sb_printf (diff) | |
download | sandbox-31599d72d7bdb0cccef5d446d3761759bd06f6bb.tar.gz sandbox-31599d72d7bdb0cccef5d446d3761759bd06f6bb.tar.bz2 sandbox-31599d72d7bdb0cccef5d446d3761759bd06f6bb.zip |
tests: add test case for libsigsegv
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | tests/Makefile.am | 5 | ||||
-rw-r--r-- | tests/libsigsegv.at | 7 | ||||
-rw-r--r-- | tests/libsigsegv_tst.c | 79 | ||||
-rw-r--r-- | tests/local.at | 2 | ||||
-rw-r--r-- | tests/sb_printf.at | 2 | ||||
-rw-r--r-- | tests/testsuite.at | 1 |
7 files changed, 100 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac index 66c1ce1..ee2534c 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,7 @@ AC_CHECK_HEADERS_ONCE([ \ limits.h \ memory.h \ signal.h \ + sigsegv.h \ stdarg.h \ stdbool.h \ stddef.h \ @@ -88,6 +89,7 @@ AC_CHECK_FUNCS_ONCE([ \ mkdir \ pathconf \ realpath \ + remove \ rmdir \ setenv \ strcasecmp \ @@ -100,8 +102,10 @@ AC_CHECK_FUNCS_ONCE([ \ strstr \ strtok_r \ ]) -dnl For librcutil -AC_CHECK_FUNCS([remove]) +AC_CHECK_LIB([sigsegv], [stackoverflow_install_handler], + [HAVE_LIBSIGSEGV=true], + [HAVE_LIBSIGSEGV=false]) +AM_CONDITIONAL(HAVE_LIBSIGSEGV, $HAVE_LIBSIGSEGV) dnl Check if gcc provides va_copy or __va_copy (for librcutil) AC_MSG_CHECKING([for va_copy]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 027cff2..4d39d55 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -46,11 +46,16 @@ check_PROGRAMS = \ utimensat-0 \ utimes-0 \ \ + libsigsegv_tst \ sb_printf_tst sb_printf_tst_CFLAGS = -I$(top_srcdir)/libsbutil -I$(top_srcdir)/libsbutil/include sb_printf_tst_LDADD = $(top_builddir)/libsbutil/libsbutil.la +if HAVE_LIBSIGSEGV +libsigsegv_tst_LDADD = -lsigsegv +endif + check-local: atconfig atlocal $(TESTSUITE) $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS) diff --git a/tests/libsigsegv.at b/tests/libsigsegv.at new file mode 100644 index 0000000..7ff03bb --- /dev/null +++ b/tests/libsigsegv.at @@ -0,0 +1,7 @@ +AT_SETUP(libsigsegv) + +AT_SB_CHECK([libsigsegv_tst], [0], [dnl +starting overflow ... caught segv ... OVERFLOW: OK! +]) + +AT_CLEANUP diff --git a/tests/libsigsegv_tst.c b/tests/libsigsegv_tst.c new file mode 100644 index 0000000..35ad246 --- /dev/null +++ b/tests/libsigsegv_tst.c @@ -0,0 +1,79 @@ +/* distilled from m4: + * $ echo 'define(a,a(a))a' | m4 + * + * Basically, we use libsigsegv to install segfault and overflow handlers. + * Then we overflow the stack. The segfault handler should be called. Then + * we return, libsigsegv detects the overflow and then calls the overflow + * handler. + */ + +#include "tests.h" + +#define WRITE(msg) write(1, msg, sizeof(msg)) + +#ifdef HAVE_SIGSEGV_H +#include <sigsegv.h> + +static int segv_handler(void *address, int serious) +{ + WRITE("caught segv ... "); + if (!serious) + return 0; + WRITE("FAIL: wtf, it's serious!"); + _exit(1); +} + + +static void overflow_handler(int emergency, stackoverflow_context_t context) +{ + WRITE("OVERFLOW: OK!\n"); + _exit(0); +} + +static union +{ + char buffer[SIGSTKSZ]; + long double ld; + long l; + void *p; +} alternate_signal_stack; + +int recursive(int i) +{ + char stack_fatty[1024]; + int ret = sprintf(stack_fatty, "%i", i); + if (i <= 0) + return i + ret; + else + return recursive(i + ret); +} + +int main(int argc, char *argv[]) +{ + int ret; + + ret = stackoverflow_install_handler(overflow_handler, + alternate_signal_stack.buffer, sizeof alternate_signal_stack.buffer); + if (ret) + err("stackoverflow_install_handler() failed"); + + ret = sigsegv_install_handler(segv_handler); + if (ret) + err("sigsegv_install_handler() failed"); + + WRITE("starting overflow ... "); + recursive(argc); + return 0; +} + +#else + +int main() +{ + WRITE("starting overflow ... "); + WRITE("caught segv ... "); + WRITE("OVERFLOW: OK!\n"); + return 0; +} + +#endif diff --git a/tests/local.at b/tests/local.at index 8b13789..3ae6933 100644 --- a/tests/local.at +++ b/tests/local.at @@ -1 +1 @@ - +m4_defun([AT_SB_CHECK],[AT_CHECK([sandbox.sh $1],[$2],[$3],[$4],[$5],[$6])]) diff --git a/tests/sb_printf.at b/tests/sb_printf.at index cbb71dc..33a17b0 100644 --- a/tests/sb_printf.at +++ b/tests/sb_printf.at @@ -1,6 +1,6 @@ AT_SETUP(sb_printf) -AT_CHECK([sb_printf_tst], [0],[dnl +AT_CHECK([sb_printf_tst], [0], [dnl 1 -1 123 diff --git a/tests/testsuite.at b/tests/testsuite.at index 7d85519..02c449f 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -1,3 +1,4 @@ AT_INIT +m4_include(libsigsegv.at) m4_include(sb_printf.at) |