summaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2020-08-07 16:39:56 -0400
committerFrans Kaashoek <[email protected]>2020-08-10 11:19:10 -0400
commit76d6c57edec14071156e7780f7e8e08c200cf166 (patch)
tree2cd4df3f0269f346c4de74b912ffbabe0d5c48ed /user
parente3b7058907dff779cf94e23bf6bb84245faf481d (diff)
downloadxv6-labs-76d6c57edec14071156e7780f7e8e08c200cf166.tar.gz
xv6-labs-76d6c57edec14071156e7780f7e8e08c200cf166.tar.bz2
xv6-labs-76d6c57edec14071156e7780f7e8e08c200cf166.zip
test copyinstr()'s handling of the terminating null
Diffstat (limited to 'user')
-rw-r--r--user/usertests.c66
1 files changed, 64 insertions, 2 deletions
diff --git a/user/usertests.c b/user/usertests.c
index 8eb4aab..5c2fc02 100644
--- a/user/usertests.c
+++ b/user/usertests.c
@@ -105,7 +105,7 @@ copyout(char *s)
}
void
-copyinstr(char *s)
+copyinstr1(char *s)
{
uint64 addrs[] = { 0x80000000LL, 0xffffffffffffffff };
@@ -120,6 +120,67 @@ copyinstr(char *s)
}
}
+void
+copyinstr2(char *s)
+{
+ char b[MAXPATH+1];
+
+ for(int i = 0; i < MAXPATH; i++)
+ b[i] = 'x';
+ b[MAXPATH] = '\0';
+
+ int ret = unlink(b);
+ if(ret != -1){
+ printf("unlink(%s) returned %d, not -1\n", b, ret);
+ exit(1);
+ }
+
+ int fd = open(b, O_CREATE | O_WRONLY);
+ if(fd != -1){
+ printf("open(%s) returned %d, not -1\n", b, fd);
+ exit(1);
+ }
+
+ ret = link(b, b);
+ if(ret != -1){
+ printf("link(%s, %s) returned %d, not -1\n", b, b, ret);
+ exit(1);
+ }
+
+ char *args[] = { "xx", 0 };
+ ret = exec(b, args);
+ if(ret != -1){
+ printf("exec(%s) returned %d, not -1\n", b, fd);
+ exit(1);
+ }
+
+ int pid = fork();
+ if(pid < 0){
+ printf("fork failed\n");
+ exit(1);
+ }
+ if(pid == 0){
+ static char big[PGSIZE+1];
+ for(int i = 0; i < PGSIZE; i++)
+ big[i] = 'x';
+ big[PGSIZE] = '\0';
+ char *args2[] = { big, big, big, 0 };
+ ret = exec("echo", args2);
+ if(ret != -1){
+ printf("exec(echo, BIG) returned %d, not -1\n", fd);
+ exit(1);
+ }
+ exit(747); // OK
+ }
+
+ int st = 0;
+ wait(&st);
+ if(st != 747){
+ printf("exec(echo, BIG) succeeded, should have failed\n");
+ exit(1);
+ }
+}
+
// test O_TRUNC.
void
truncate1(char *s)
@@ -2407,7 +2468,8 @@ main(int argc, char *argv[])
} tests[] = {
{copyin, "copyin"},
{copyout, "copyout"},
- {copyinstr, "copyinstr"},
+ {copyinstr1, "copyinstr1"},
+ {copyinstr2, "copyinstr2"},
{truncate1, "truncate1"},
{truncate2, "truncate2"},
{truncate3, "truncate3"},