aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-06-14 14:30:16 -0700
committerPaul Eggert2011-06-14 14:30:16 -0700
commitdd0b0efbabfc187be6810a0e41b4ac5fdda667af (patch)
tree227c0b03effa5d98f23d67e152e8fafb61b9fa63 /src
parent86fe5cfe4de95a44b949db9be105e78497318804 (diff)
downloademacs-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')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/alloc.c25
2 files changed, 22 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 7bd1d47b328..dd61843bc85 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,12 @@
12011-06-14 Paul Eggert <eggert@cs.ucla.edu> 12011-06-14 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * alloc.c: Check that resized vectors' lengths fit in fixnums.
4 (header_size, word_size): New constants.
5 (allocate_vectorlike): Don't check size overflow here.
6 (allocate_vector): Check it here instead, since this is the only
7 caller of allocate_vectorlike that could cause overflow.
8 Check that the new vector's length is representable as a fixnum.
9
3 * fns.c (next_almost_prime): Don't return a multiple of 3 or 5. 10 * fns.c (next_almost_prime): Don't return a multiple of 3 or 5.
4 The previous code was bogus. For example, next_almost_prime (32) 11 The previous code was bogus. For example, next_almost_prime (32)
5 returned 39, which is undesirable as it is a multiple of 3; and 12 returned 39, which is undesirable as it is a multiple of 3; and
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
2768static struct Lisp_Vector *all_vectors; 2768static struct Lisp_Vector *all_vectors;
2769 2769
2770/* Handy constants for vectorlike objects. */
2771enum
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
2820struct Lisp_Vector * 2820struct Lisp_Vector *
2821allocate_vector (EMACS_INT nslots) 2821allocate_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