diff options
| author | Paul Eggert | 2011-06-14 14:30:16 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-14 14:30:16 -0700 |
| commit | dd0b0efbabfc187be6810a0e41b4ac5fdda667af (patch) | |
| tree | 227c0b03effa5d98f23d67e152e8fafb61b9fa63 /src/alloc.c | |
| parent | 86fe5cfe4de95a44b949db9be105e78497318804 (diff) | |
| download | emacs-dd0b0efbabfc187be6810a0e41b4ac5fdda667af.tar.gz emacs-dd0b0efbabfc187be6810a0e41b4ac5fdda667af.zip | |
* alloc.c: Check that resized vectors' lengths fit in fixnums.
(header_size, word_size): New constants.
(allocate_vectorlike): Don't check size overflow here.
(allocate_vector): Check it here instead, since this is the only
caller of allocate_vectorlike that could cause overflow.
Check that the new vector's length is representable as a fixnum.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/alloc.c b/src/alloc.c index 56e8eb4d465..00d330c1b6a 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -2767,6 +2767,12 @@ DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0, | |||
| 2767 | 2767 | ||
| 2768 | static struct Lisp_Vector *all_vectors; | 2768 | static struct Lisp_Vector *all_vectors; |
| 2769 | 2769 | ||
| 2770 | /* Handy constants for vectorlike objects. */ | ||
| 2771 | enum | ||
| 2772 | { | ||
| 2773 | header_size = offsetof (struct Lisp_Vector, contents), | ||
| 2774 | word_size = sizeof (Lisp_Object) | ||
| 2775 | }; | ||
| 2770 | 2776 | ||
| 2771 | /* Value is a pointer to a newly allocated Lisp_Vector structure | 2777 | /* Value is a pointer to a newly allocated Lisp_Vector structure |
| 2772 | with room for LEN Lisp_Objects. */ | 2778 | with room for LEN Lisp_Objects. */ |
| @@ -2776,12 +2782,6 @@ allocate_vectorlike (EMACS_INT len) | |||
| 2776 | { | 2782 | { |
| 2777 | struct Lisp_Vector *p; | 2783 | struct Lisp_Vector *p; |
| 2778 | size_t nbytes; | 2784 | size_t nbytes; |
| 2779 | ptrdiff_t nbytes_max = min (PTRDIFF_MAX, SIZE_MAX); | ||
| 2780 | int header_size = offsetof (struct Lisp_Vector, contents); | ||
| 2781 | int word_size = sizeof p->contents[0]; | ||
| 2782 | |||
| 2783 | if ((nbytes_max - header_size) / word_size < len) | ||
| 2784 | memory_full (SIZE_MAX); | ||
| 2785 | 2785 | ||
| 2786 | MALLOC_BLOCK_INPUT; | 2786 | MALLOC_BLOCK_INPUT; |
| 2787 | 2787 | ||
| @@ -2815,13 +2815,18 @@ allocate_vectorlike (EMACS_INT len) | |||
| 2815 | } | 2815 | } |
| 2816 | 2816 | ||
| 2817 | 2817 | ||
| 2818 | /* Allocate a vector with NSLOTS slots. */ | 2818 | /* Allocate a vector with LEN slots. */ |
| 2819 | 2819 | ||
| 2820 | struct Lisp_Vector * | 2820 | struct Lisp_Vector * |
| 2821 | allocate_vector (EMACS_INT nslots) | 2821 | allocate_vector (EMACS_INT len) |
| 2822 | { | 2822 | { |
| 2823 | struct Lisp_Vector *v = allocate_vectorlike (nslots); | 2823 | struct Lisp_Vector *v; |
| 2824 | v->header.size = nslots; | 2824 | ptrdiff_t nbytes_max = min (PTRDIFF_MAX, SIZE_MAX); |
| 2825 | |||
| 2826 | if (min ((nbytes_max - header_size) / word_size, MOST_POSITIVE_FIXNUM) < len) | ||
| 2827 | memory_full (SIZE_MAX); | ||
| 2828 | v = allocate_vectorlike (len); | ||
| 2829 | v->header.size = len; | ||
| 2825 | return v; | 2830 | return v; |
| 2826 | } | 2831 | } |
| 2827 | 2832 | ||