#include #include #include #include #include #include #include /** ** \file depends: sysconf, mmap, mprotect, open, signal, sigsetjmp, siglongjmp, fprintf ** \author Luka Marčetić, 2011 **/ //necessary to detect errors, and resume afterwards: int next; ///< number of the currently executing test, or greater on failure sigjmp_buf env; ///< will store the signal mask and stack context/environment void bridge_sig_jmp(int sig); void print_result(int done, char *name); /** ** Tests string/memory functions for invalid memory access ** and for correctnes when handling 'high' vs 'low' bytes. ** ** tests: strchr, strlen, strspn, strcspn, memchr **/ int main() { int i, j, k, fd, tmpi, pg_size=sysconf(_SC_PAGESIZE); char *tmp, *m; char low=' ', high=128+low, string[]="\x20\x40\x60\x80\xA0\xC0\xE0"; fd = open("/dev/zero", O_RDWR); m = mmap(NULL, pg_size*2, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); mprotect(m+pg_size, pg_size, PROT_NONE); signal(SIGSEGV, bridge_sig_jmp); next=0; switch (sigsetjmp(env, 1)) { case 0: //strchr: fprintf(stdout, " strchr\n"); for (i=0; i done) fprintf (stderr, " %s: Failure\n", name); else { fprintf (stdout, " %s: Success\n", name); next = done+1; } return; }