summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--userprog/process.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/userprog/process.c b/userprog/process.c
index bf1a706..741503b 100644
--- a/userprog/process.c
+++ b/userprog/process.c
@@ -614,11 +614,17 @@ setup_stack (uint32_t **esp, const char *args)
614 stack_end = PHYS_BASE - PGSIZE; 614 stack_end = PHYS_BASE - PGSIZE;
615 stack_end += 4 + 1; 615 stack_end += 4 + 1;
616 616
617 /* copy arguments to stack */ 617 /* check if arguments fits into our stack */
618 argslen = strlen(args); 618 argslen = strlen(args);
619 if (argslen > 0) 619 if (argslen > 0)
620 argslen += 1; /* add the trailing \0 */
621 namelen = strlen(name) + 1;
622 if (*esp - argslen - namelen <= stack_end)
623 return false;
624
625 /* copy arguments to stack */
626 if (argslen > 0)
620 { 627 {
621 argslen += 1; /* add the trailing \0 */
622 *(char **) esp -= argslen; 628 *(char **) esp -= argslen;
623 memcpy(*esp, args, argslen); 629 memcpy(*esp, args, argslen);
624 } 630 }
@@ -628,7 +634,7 @@ setup_stack (uint32_t **esp, const char *args)
628 *(char **) esp -= namelen; 634 *(char **) esp -= namelen;
629 memcpy(*esp, name, namelen); 635 memcpy(*esp, name, namelen);
630 636
631 /* align our currend address by word-size (thanks to thomas & edy) */ 637 /* align our current address by word-size */
632 *(char **) esp -= (sizeof(uint32_t) - (PHYS_BASE - *(void **) esp) % sizeof(uint32_t)); 638 *(char **) esp -= (sizeof(uint32_t) - (PHYS_BASE - *(void **) esp) % sizeof(uint32_t));
633 639
634 /* terminate argv[] array by NULL ptr */ 640 /* terminate argv[] array by NULL ptr */