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;