From 99938681206bc944f55e77472b6443992159822a Mon Sep 17 00:00:00 2001
From: Joshua Saxby <joshua.a.saxby@gmail.com>
Date: Thu, 5 Dec 2019 10:20:26 +0000
Subject: [PATCH] Fix a nasty bug in write(). DOn't allow writing to the
 keyboard!

---
 userprog/syscall_write.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/userprog/syscall_write.c b/userprog/syscall_write.c
index 9c356db..525e2cf 100644
--- a/userprog/syscall_write.c
+++ b/userprog/syscall_write.c
@@ -21,7 +21,10 @@ void syscall_write(struct intr_frame *f) {
     unsigned size = *((unsigned*)((int*)f->esp + 3)); // size to write is fourth
     // writing to stdout or stderr (fd in {1, 2}) is a special case
     switch (fd) {
-    case 1: // stdin
+    case 0: // writing to stdin (keyboard) is an error condition
+        f->eax = 0;
+        break;
+    case 1: // stdout
     case 2: // stderr
         write_to_console((const char*)buffer, size);
         f->eax = size;
-- 
GitLab