summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authordzwdz2022-07-17 20:59:23 +0200
committerdzwdz2022-07-17 20:59:23 +0200
commit620bd6af8e005057e04c8a2891c7537ec3556345 (patch)
tree14e8f078b2374c1efaf8724a04370768fe750547 /src/user
parentc6bbf615e5c77ec273b954c11cef95df3d6f7286 (diff)
amd64: ensure all addresses are canonical
Diffstat (limited to 'src/user')
-rw-r--r--src/user/tests/main.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/user/tests/main.c b/src/user/tests/main.c
index b4587f9..ab6b4a8 100644
--- a/src/user/tests/main.c
+++ b/src/user/tests/main.c
@@ -189,13 +189,35 @@ static void test_malloc(void) {
}
static void test_efault(void) {
+ const char *str = "o, 16 characters";
+ char str2[16];
char *invalid = (void*)0x1000;
handle_t h;
+ memcpy(str2, str, 16);
+
assert((h = _syscall_open(tmpfilepath, strlen(tmpfilepath), OPEN_CREATE)));
- assert(_syscall_write(h, "dzwdz sucks ass!", 16, 0) == 16);
+ assert(_syscall_write(h, str, 16, 0) == 16);
+ assert(_syscall_write(h, str2, 16, 0) == 16);
+
assert(_syscall_write(h, invalid, 16, 0) == -EFAULT);
- assert(_syscall_write(h, "dzwdz is cool!!!", 16, 0) == 16);
+
+ /* x64 canonical pointers */
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x8000000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x1000000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0100000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0010000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0001000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0000800000000000), 16, 0) == -EFAULT);
+
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x8000000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x1000000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0100000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0010000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0001000000000000), 16, 0) == -EFAULT);
+ assert(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0000800000000000), 16, 0) == -EFAULT);
+
+ assert(_syscall_write(h, str, 16, 0) == 16);
close(h);
}