From 3a258cf064c51f6f69df48a5bf37de9097f337c7 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Mon, 4 Nov 2024 00:38:58 +0000 Subject: [PATCH] Update validate_user_pointer to perform no memory checks when size is 0 --- src/userprog/syscall.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index ddbbd39..fc8c28e 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -80,11 +80,15 @@ exit (int status UNUSED) } /* Validates if a block of memory starting at PTR and of size SIZE bytes is - fully contained within user virtual memory. */ + fully contained within user virtual memory. Kills the thread (by calling + thread_exit) if the memory is invalid. Otherwise, returns the PTR given. + If the size is 0, the function does no checks and returns PTR.*/ static void * validate_user_pointer (void *ptr, size_t size) { - if (ptr == NULL || !is_user_vaddr (ptr) || !is_user_vaddr (ptr + size - 1)) + if (size > 0 && (ptr == NULL || + !is_user_vaddr (ptr) || + !is_user_vaddr (ptr + size - 1))) thread_exit (); return ptr;