diff options
| -rw-r--r-- | userprog/process.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/userprog/process.c b/userprog/process.c index fdfb5dd..c13c051 100644 --- a/userprog/process.c +++ b/userprog/process.c | |||
| @@ -595,7 +595,8 @@ setup_stack (uint32_t **esp, const char *args) | |||
| 595 | const char *name = thread_current ()->name; | 595 | const char *name = thread_current ()->name; |
| 596 | char *argv_cur; | 596 | char *argv_cur; |
| 597 | uint32_t argc = 0; | 597 | uint32_t argc = 0; |
| 598 | unsigned namelen, argslen = strlen(args); | 598 | unsigned namelen, argslen = 0; |
| 599 | uint32_t *stack_end; | ||
| 599 | 600 | ||
| 600 | kpage = palloc_get_page (PAL_USER | PAL_ZERO); | 601 | kpage = palloc_get_page (PAL_USER | PAL_ZERO); |
| 601 | if (kpage == NULL) | 602 | if (kpage == NULL) |
| @@ -608,7 +609,14 @@ setup_stack (uint32_t **esp, const char *args) | |||
| 608 | 609 | ||
| 609 | *esp = PHYS_BASE; | 610 | *esp = PHYS_BASE; |
| 610 | 611 | ||
| 612 | /* calculate end of stack which we'll enforce, | ||
| 613 | we need at least 4 entries for a correct stack and an | ||
| 614 | additional entry due to the way our argv[]-entries-loop works */ | ||
| 615 | stack_end = PHYS_BASE - PGSIZE; | ||
| 616 | stack_end += 4 + 1; | ||
| 617 | |||
| 611 | /* copy arguments to stack */ | 618 | /* copy arguments to stack */ |
| 619 | argslen = strlen(args); | ||
| 612 | if (argslen > 0) | 620 | if (argslen > 0) |
| 613 | { | 621 | { |
| 614 | argslen += 1; /* add the trailing \0 */ | 622 | argslen += 1; /* add the trailing \0 */ |
| @@ -651,6 +659,10 @@ setup_stack (uint32_t **esp, const char *args) | |||
| 651 | (*esp)--; | 659 | (*esp)--; |
| 652 | **esp = (uint32_t) argv_cur + 1; | 660 | **esp = (uint32_t) argv_cur + 1; |
| 653 | argc++; | 661 | argc++; |
| 662 | |||
| 663 | /* check for possible stack overflow */ | ||
| 664 | if (*esp <= stack_end) | ||
| 665 | return false; | ||
| 654 | } | 666 | } |
| 655 | } | 667 | } |
| 656 | } | 668 | } |
