From 79f6a8e8080dfd2fc15fd9bd31dc0365600c4600 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Mon, 4 Nov 2024 00:44:55 +0000 Subject: [PATCH] Fix Bug in syscall handler related to pointer arithmetic: add sizeof uintptr_t instead of 1 --- src/userprog/syscall.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index fc8c28e..e2f0163 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -57,10 +57,11 @@ syscall_handler (struct intr_frame *f) syscall_arguments syscall = syscall_lookup[syscall_number]; /* Next, read and copy the arguments from the stack pointer. */ - validate_user_pointer (f->esp, syscall.arity); - uintptr_t args[3]; + validate_user_pointer (f->esp + sizeof (uintptr_t), + syscall.arity * sizeof (uintptr_t)); + uintptr_t args[3] = {0}; for (int i=0; i < syscall.arity; i++) - args[i] = *(uintptr_t *) (f->esp + 1 + i); + args[i] = *(uintptr_t *) (f->esp + sizeof (uintptr_t) * (i + 1)); /* Call the function that handles this system call with the arguments. When there is a return value it is stored in f->eax. */