diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-03-14 13:28:01 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-03-14 13:34:36 +0100 |
| commit | 20fa5aa70d2a5e599ea2604f51baa49c6e891ab3 (patch) | |
| tree | db5bc904bf8387e35c82a622abedf63c6512498a /src/userprog/syscall.c | |
| parent | f8b7ad12f3843134352efd9da7062f3db34283d6 (diff) | |
| download | pintos-20fa5aa70d2a5e599ea2604f51baa49c6e891ab3.tar.gz | |
check all pointers before dereferencing
Diffstat (limited to 'src/userprog/syscall.c')
| -rw-r--r-- | src/userprog/syscall.c | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 4d2ce7a..e845edb 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -159,9 +159,9 @@ close (int fd_i) } static pid_t -exec (const char *file_name) +exec (const char *filename) { - return process_execute (file_name); + return process_execute (filename); } static bool @@ -199,6 +199,13 @@ syscall_handler (struct intr_frame *f UNUSED) CHECK_PTR_AND_MAYBE_EXIT (syscall_number); + char **filename; + int *status, *fd_i; + off_t *initial_size; + tid_t *child_tid; + unsigned *size; + void **buf; + switch (*syscall_number) { case 0: // halt @@ -206,35 +213,65 @@ syscall_handler (struct intr_frame *f UNUSED) break; case 1: // exit - exit (*INTR_ESP (1, int)); + status = INTR_ESP (1, int); + CHECK_PTR_AND_MAYBE_EXIT (status); + exit (*status); break; case 2: // exec - f->eax = exec (*INTR_ESP (1, char *)); + filename = INTR_ESP (1, char *); + CHECK_PTR_AND_MAYBE_EXIT (filename); + CHECK_PTR_AND_MAYBE_EXIT (*filename); + f->eax = exec (*filename); break; case 3: // wait - f->eax = wait (*INTR_ESP (1, tid_t)); + child_tid = INTR_ESP (1, tid_t); + CHECK_PTR_AND_MAYBE_EXIT (child_tid); + f->eax = wait (*child_tid); break; case 4: // create - f->eax = create (*INTR_ESP (1, char *), *INTR_ESP (2, off_t)); + filename = INTR_ESP (1, char *); + initial_size = INTR_ESP (2, off_t); + CHECK_PTR_AND_MAYBE_EXIT (filename); + CHECK_PTR_AND_MAYBE_EXIT (*filename); + CHECK_PTR_AND_MAYBE_EXIT (initial_size); + f->eax = create (*filename, *initial_size); break; case 6: // open - f->eax = open (*INTR_ESP (1, char *)); + filename = INTR_ESP (1, char *); + CHECK_PTR_AND_MAYBE_EXIT (filename); + CHECK_PTR_AND_MAYBE_EXIT (*filename); + f->eax = open (*filename); break; case 8: // read - f->eax = read (*INTR_ESP (1, int), *INTR_ESP (2, void *), *INTR_ESP (3, unsigned)); + fd_i = INTR_ESP (1, int); + buf = INTR_ESP (2, void *); + size = INTR_ESP (3, unsigned); + CHECK_PTR_AND_MAYBE_EXIT (fd_i); + CHECK_PTR_AND_MAYBE_EXIT (buf); + CHECK_PTR_AND_MAYBE_EXIT (*buf); + CHECK_PTR_AND_MAYBE_EXIT (size); + f->eax = read (*fd_i, *buf, *size); break; case 9: // write - f->eax = write (*INTR_ESP (1, int), *INTR_ESP (2, const void *), *INTR_ESP (3, unsigned)); + fd_i = INTR_ESP (1, int); + buf = INTR_ESP (2, void *); + size = INTR_ESP (3, unsigned); + CHECK_PTR_AND_MAYBE_EXIT (fd_i); + CHECK_PTR_AND_MAYBE_EXIT (buf); + CHECK_PTR_AND_MAYBE_EXIT (*buf); + CHECK_PTR_AND_MAYBE_EXIT (size); + f->eax = write (*fd_i, *buf, *size); break; case 12: // close - close (*INTR_ESP (1, int)); + fd_i = INTR_ESP (1, int); + close (*fd_i); break; default: printf ("kernel: unknown syscall '%d'\n", *syscall_number); |
