]> Zhao Yanbai Git Server - minix.git/commitdiff
test44: add bogus getsysinfo() to test invalid memory range request to vm
authorBen Gras <ben@minix3.org>
Sat, 10 Jul 2010 00:24:43 +0000 (00:24 +0000)
committerBen Gras <ben@minix3.org>
Sat, 10 Jul 2010 00:24:43 +0000 (00:24 +0000)
test case contributed by Roman Ignatov.

test/test44.c

index 4f9e7346601b016d6b8cbb68bd98ebee91bbbc61..96aff0ef38ed86c5c9a8ce6173c083b2df503dff 100644 (file)
@@ -3,7 +3,10 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <errno.h>
+#include <minix/com.h>
 #include <sys/mman.h>
+#include <sys/wait.h>
 
 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);
 }
-