From 0f1bce2e88b0367020d2820e80b4fea55bcace9c Mon Sep 17 00:00:00 2001 From: sBubshait Date: Fri, 15 Nov 2024 14:52:21 +0000 Subject: [PATCH] Refactor process_init_stack to add asserts and comments --- src/userprog/process.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/userprog/process.c b/src/userprog/process.c index ad0bdec..02a5274 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -191,6 +191,10 @@ start_process (void *proc_start_data) static bool process_init_stack (char *cmd_saveptr, void **esp, char *file_name) { + ASSERT (cmd_saveptr != NULL); + ASSERT (esp != NULL); + ASSERT (file_name != NULL); + /* Load command line argument *data* to user process stack. This can't cause overflow due to enforcing that the size of command line input must fit in a page. Also keep track @@ -202,7 +206,10 @@ process_init_stack (char *cmd_saveptr, void **esp, char *file_name) int arg_count = 0; while (arg != NULL) { - push_to_stack (esp, arg, (strlen (arg) + 1) * sizeof (char)); + /* filename has already been validated to be a safe-to-access string, + so we can safely use strlen here. Filename has already been + split from the command line arguments. */ + push_to_stack (esp, arg, strlen (arg) + 1); struct arg_elem *arg_elem = malloc (sizeof (struct arg_elem)); if (arg_elem == NULL)