From: Ben Gras Date: Sat, 10 Jul 2010 00:24:43 +0000 (+0000) Subject: test44: add bogus getsysinfo() to test invalid memory range request to vm X-Git-Tag: v3.1.8~265 X-Git-Url: http://zhaoyanbai.com/repos/pkcs11-list.html?a=commitdiff_plain;h=b4345d7598af5a091de254950af5b73022c1862c;p=minix.git test44: add bogus getsysinfo() to test invalid memory range request to vm test case contributed by Roman Ignatov. --- diff --git a/test/test44.c b/test/test44.c index 4f9e73466..96aff0ef3 100644 --- a/test/test44.c +++ b/test/test44.c @@ -3,7 +3,10 @@ #include #include #include +#include +#include #include +#include int main(int argc, char *argv[]) @@ -17,6 +20,7 @@ main(int argc, char *argv[]) #define STARTV 0x90000000 char *vaddr = (char *) STARTV; ssize_t l; + pid_t f; printf("Test 44 "); fflush(stdout); @@ -60,8 +64,45 @@ main(int argc, char *argv[]) } } + /* Now start a child to test bogus memory access */ + if((f = fork()) == -1) { + perror("fork"); + exit(1); + } + + if(f > 0) { + int st; + /* Parent waits. */ + if(waitpid(f, &st, 0) < 0) { + perror("waitpid"); + exit(1); + } + if(!WIFEXITED(st)) { + fprintf(stderr, "child not signaled\n"); + exit(1); + } + if(WEXITSTATUS(st) != 0) { + fprintf(stderr, "child exited with nonzero status\n"); + exit(1); + } + } else { + /* Child performs bogus getsysinfo */ + int res; + char *buf = v[CHUNKS-1]; + errno = 0; + res = getsysinfo( PM_PROC_NR, SI_PROC_TAB, buf); + if(res >= 0) { + fprintf(stderr, "res %d\n", res); + exit(1); + } + if(errno != EFAULT) { + fprintf(stderr, "errno %d\n", errno); + exit(1); + } + exit(0); + } + printf("ok\n"); exit(0); } -