aboutsummaryrefslogtreecommitdiffstats
path: root/src/ChangeLog
diff options
context:
space:
mode:
authorPaul Eggert2011-06-15 12:57:25 -0700
committerPaul Eggert2011-06-15 12:57:25 -0700
commita7af7fdede602a111401c2352e81311a9dc38b99 (patch)
treedaebcb8a73345231337d0a461c01ae7804b2b646 /src/ChangeLog
parent8c9b210626493dd93f236d7fb312c4f6dba62892 (diff)
parentb1c46f026de9d185ba86ffb1b23c50f2bd095ccf (diff)
downloademacs-a7af7fdede602a111401c2352e81311a9dc38b99.tar.gz
emacs-a7af7fdede602a111401c2352e81311a9dc38b99.zip
Integer overflow and signedness fixes (Bug#8873).
Diffstat (limited to 'src/ChangeLog')
-rw-r--r--src/ChangeLog250
1 files changed, 250 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 821e4090cfd..59fb2d89b24 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,253 @@
12011-06-15 Paul Eggert <eggert@cs.ucla.edu>
2
3 Integer overflow and signedness fixes (Bug#8873).
4
5 * ccl.c (ASCENDING_ORDER): New macro, to work around GCC bug 43772.
6 (GET_CCL_RANGE, IN_INT_RANGE): Use it.
7
8 * fileio.c: Don't assume EMACS_INT fits in off_t.
9 (emacs_lseek): New static function.
10 (Finsert_file_contents, Fwrite_region): Use it.
11 Use SEEK_SET, SEEK_CUR, SEEK_END as appropriate.
12
13 * fns.c (Fload_average): Don't assume 100 * load average fits in int.
14
15 * fns.c: Don't overflow int when computing a list length.
16 * fns.c (QUIT_COUNT_HEURISTIC): New constant.
17 (Flength, Fsafe_length): Use EMACS_INT, not int, to avoid unwanted
18 truncation on 64-bit hosts. Check for QUIT every
19 QUIT_COUNT_HEURISTIC entries rather than every other entry; that's
20 faster and is responsive enough.
21 (Flength): Report an error instead of overflowing an integer.
22 (Fsafe_length): Return a float if the value is not representable
23 as a fixnum. This shouldn't happen except in contrived situations.
24 (Fnthcdr, Fsort): Don't assume list length fits in int.
25 (Fcopy_sequence): Don't assume vector length fits in int.
26
27 * alloc.c: Check that resized vectors' lengths fit in fixnums.
28 (header_size, word_size): New constants.
29 (allocate_vectorlike): Don't check size overflow here.
30 (allocate_vector): Check it here instead, since this is the only
31 caller of allocate_vectorlike that could cause overflow.
32 Check that the new vector's length is representable as a fixnum.
33
34 * fns.c (next_almost_prime): Don't return a multiple of 3 or 5.
35 The previous code was bogus. For example, next_almost_prime (32)
36 returned 39, which is undesirable as it is a multiple of 3; and
37 next_almost_prime (24) returned 25, which is a multiple of 5 so
38 why was the code bothering to check for multiples of 7?
39
40 * bytecode.c (exec_byte_code): Use ptrdiff_t, not int, for vector length.
41
42 * eval.c, doprnt.c (SIZE_MAX): Remove; inttypes.h defines this now.
43
44 Variadic C functions now count arguments with ptrdiff_t.
45 This partly undoes my 2011-03-30 change, which replaced int with size_t.
46 Back then I didn't know that the Emacs coding style prefers signed int.
47 Also, in the meantime I found a few more instances where arguments
48 were being counted with int, which may truncate counts on 64-bit
49 machines, or EMACS_INT, which may be unnecessarily wide.
50 * lisp.h (struct Lisp_Subr.function.aMANY)
51 (DEFUN_ARGS_MANY, internal_condition_case_n, safe_call):
52 Arg counts are now ptrdiff_t, not size_t.
53 All variadic functions and their callers changed accordingly.
54 (struct gcpro.nvars): Now size_t, not size_t. All uses changed.
55 * bytecode.c (exec_byte_code): Check maxdepth for overflow,
56 to avoid potential buffer overrun. Don't assume arg counts fit in 'int'.
57 * callint.c (Fcall_interactively): Check arg count for overflow,
58 to avoid potential buffer overrun. Use signed char, not 'int',
59 for 'varies' array, so that we needn't bother to check its size
60 calculation for overflow.
61 * editfns.c (Fformat): Use ptrdiff_t, not EMACS_INT, to count args.
62 * eval.c (apply_lambda):
63 * fns.c (Fmapconcat): Use XFASTINT, not XINT, to get args length.
64 (struct textprop_rec.argnum): Now ptrdiff_t, not int. All uses changed.
65 (mapconcat): Use ptrdiff_t, not int and EMACS_INT, to count args.
66
67 * callint.c (Fcall_interactively): Don't use index var as event count.
68
69 * vm-limit.c (check_memory_limits): Fix incorrect extern function decls.
70 * mem-limits.h (SIZE): Remove; no longer used.
71
72 * xterm.c (x_alloc_nearest_color_1): Prefer int to long when int works.
73
74 Remove unnecessary casts.
75 * xterm.c (x_term_init):
76 * xfns.c (x_set_border_pixel):
77 * widget.c (create_frame_gcs): Remove casts to unsigned long etc.
78 These aren't needed now that we assume ANSI C.
79
80 * sound.c (Fplay_sound_internal): Remove cast to unsigned long.
81 It's more likely to cause problems (due to unsigned overflow)
82 than to cure them.
83
84 * dired.c (Ffile_attributes): Don't use 32-bit hack on 64-bit hosts.
85
86 * unexelf.c (unexec): Don't assume BSS addr fits in unsigned.
87
88 * xterm.c (handle_one_xevent): Omit unnecessary casts to unsigned.
89
90 * keyboard.c (modify_event_symbol): Don't limit alist len to UINT_MAX.
91
92 * lisp.h (CHAR_TABLE_SET): Omit now-redundant test.
93
94 * lread.c (Fload): Don't compare a possibly-garbage time_t value.
95
96 GLYPH_CODE_FACE returns EMACS_INT, not int.
97 * dispextern.h (merge_faces):
98 * xfaces.c (merge_faces):
99 * xdisp.c (get_next_display_element, next_element_from_display_vector):
100 Don't assume EMACS_INT fits in int.
101
102 * character.h (CHAR_VALID_P): Remove unused parameter.
103 * fontset.c, lisp.h, xdisp.c: All uses changed.
104
105 * editfns.c (Ftranslate_region_internal): Omit redundant test.
106
107 * fns.c (concat): Minor tuning based on overflow analysis.
108 This doesn't fix any bugs. Use int to hold character, instead
109 of constantly refetching from Emacs object. Use XFASTINT, not
110 XINT, for value known to be a character. Don't bother comparing
111 a single byte to 0400, as it's always less.
112
113 * floatfns.c (Fexpt):
114 * fileio.c (make_temp_name): Omit unnecessary cast to unsigned.
115
116 * editfns.c (Ftranslate_region_internal): Use int, not EMACS_INT
117 for characters.
118
119 * doc.c (get_doc_string): Omit (unsigned)c that mishandled negatives.
120
121 * data.c (Faset): If ARRAY is a string, check that NEWELT is a char.
122 Without this fix, on a 64-bit host (aset S 0 4294967386) would
123 incorrectly succeed when S was a string, because 4294967386 was
124 truncated before it was used.
125
126 * chartab.c (Fchar_table_range): Use CHARACTERP to check range.
127 Otherwise, an out-of-range integer could cause undefined behavior
128 on a 64-bit host.
129
130 * composite.c: Use int, not EMACS_INT, for characters.
131 (fill_gstring_body, composition_compute_stop_pos): Use int, not
132 EMACS_INT, for values that are known to be in character range.
133 This doesn't fix any bugs but is the usual style inside Emacs and
134 may generate better code on 32-bit machines.
135
136 Make sure a 64-bit char is never passed to ENCODE_CHAR.
137 This is for reasons similar to the recent CHAR_STRING fix.
138 * charset.c (Fencode_char): Check that character arg is actually
139 a character. Pass an int to ENCODE_CHAR.
140 * charset.h (ENCODE_CHAR): Verify that the character argument is no
141 wider than 'int', as a compile-time check to prevent future regressions
142 in this area.
143
144 * character.c (char_string): Remove unnecessary casts.
145
146 Make sure a 64-bit char is never passed to CHAR_STRING.
147 Otherwise, CHAR_STRING would do the wrong thing on a 64-bit platform,
148 by silently ignoring the top 32 bits, allowing some values
149 that were far too large to be valid characters.
150 * character.h: Include <verify.h>.
151 (CHAR_STRING, CHAR_STRING_ADVANCE): Verify that the character
152 arguments are no wider than unsigned, as a compile-time check
153 to prevent future regressions in this area.
154 * data.c (Faset):
155 * editfns.c (Fchar_to_string, general_insert_function, Finsert_char)
156 (Fsubst_char_in_region):
157 * fns.c (concat):
158 * xdisp.c (decode_mode_spec_coding):
159 Adjust to CHAR_STRING's new requirement.
160 * editfns.c (Finsert_char, Fsubst_char_in_region):
161 * fns.c (concat): Check that character args are actually
162 characters. Without this test, these functions did the wrong
163 thing with wildly out-of-range values on 64-bit hosts.
164
165 Remove incorrect casts to 'unsigned' that lose info on 64-bit hosts.
166 These casts should not be needed on 32-bit hosts, either.
167 * keyboard.c (read_char):
168 * lread.c (Fload): Remove casts to unsigned.
169
170 * lisp.h (UNSIGNED_CMP): New macro.
171 This fixes comparison bugs on 64-bit hosts.
172 (ASCII_CHAR_P): Use it.
173 * casefiddle.c (casify_object):
174 * character.h (ASCII_BYTE_P, CHAR_VALID_P)
175 (SINGLE_BYTE_CHAR_P, CHAR_STRING):
176 * composite.h (COMPOSITION_ENCODE_RULE_VALID):
177 * dispextern.h (FACE_FROM_ID):
178 * keyboard.c (read_char): Use UNSIGNED_CMP.
179
180 * xmenu.c (dialog_selection_callback) [!USE_GTK]: Cast to intptr_t,
181 not to EMACS_INT, to avoid GCC warning.
182
183 * xfns.c (x_set_scroll_bar_default_width): Remove unused 'int' locals.
184
185 * buffer.h (PTR_BYTE_POS, BUF_PTR_BYTE_POS): Remove harmful cast.
186 The cast incorrectly truncated 64-bit byte offsets to 32 bits, and
187 isn't needed on 32-bit machines.
188
189 * buffer.c (Fgenerate_new_buffer_name):
190 Use EMACS_INT for count, not int.
191 (advance_to_char_boundary): Return EMACS_INT, not int.
192
193 * data.c (Qcompiled_function): Now static.
194
195 * window.c (window_body_lines): Now static.
196
197 * image.c (gif_load): Rename local to avoid shadowing.
198
199 * lisp.h (SAFE_ALLOCA_LISP): Check for integer overflow.
200 (struct Lisp_Save_Value): Use ptrdiff_t, not int, for 'integer' member.
201 * alloc.c (make_save_value): Integer argument is now of type
202 ptrdiff_t, not int.
203 (mark_object): Use ptrdiff_t, not int.
204 * lisp.h (pD): New macro.
205 * print.c (print_object): Use it.
206
207 * alloc.c: Use EMACS_INT, not int, to count objects.
208 (total_conses, total_markers, total_symbols, total_vector_size)
209 (total_free_conses, total_free_markers, total_free_symbols)
210 (total_free_floats, total_floats, total_free_intervals)
211 (total_intervals, total_strings, total_free_strings):
212 Now EMACS_INT, not int. All uses changed.
213 (Fgarbage_collect): Compute overall total using a double, so that
214 integer overflow is less likely to be a problem. Check for overflow
215 when converting back to an integer.
216 (n_interval_blocks, n_string_blocks, n_float_blocks, n_cons_blocks)
217 (n_vectors, n_symbol_blocks, n_marker_blocks): Remove.
218 These were 'int' variables that could overflow on 64-bit hosts;
219 they were never used, so remove them instead of repairing them.
220 (nzombies, ngcs, max_live, max_zombies): Now EMACS_INT, not 'int'.
221 (inhibit_garbage_collection): Set gc_cons_threshold to max value.
222 Previously, this ceilinged at INT_MAX, but that doesn't work on
223 64-bit machines.
224 (allocate_pseudovector): Don't use EMACS_INT when int would do.
225
226 * alloc.c (Fmake_bool_vector): Don't assume vector size fits in int.
227 (allocate_vectorlike): Check for ptrdiff_t overflow.
228 (mark_vectorlike, mark_char_table, mark_object): Avoid EMACS_UINT
229 when a (possibly-narrower) signed value would do just as well.
230 We prefer using signed arithmetic, to avoid comparison confusion.
231
232 * alloc.c: Catch some string size overflows that we were missing.
233 (XMALLOC_OVERRUN_CHECK_SIZE) [!XMALLOC_OVERRUN_CHECK]: Define to 0,
234 for convenience in STRING_BYTES_MAX.
235 (STRING_BYTES_MAX): New macro, superseding the old one in lisp.h.
236 The definition here is exact; the one in lisp.h was approximate.
237 (allocate_string_data): Check for string overflow. This catches
238 some instances we weren't catching before. Also, it catches
239 size_t overflow on (unusual) hosts where SIZE_MAX <= min
240 (PTRDIFF_MAX, MOST_POSITIVE_FIXNUM), e.g., when size_t is 32 bits
241 and ptrdiff_t and EMACS_INT are both 64 bits.
242
243 * character.c, coding.c, doprnt.c, editfns.c, eval.c:
244 All uses of STRING_BYTES_MAX replaced by STRING_BYTES_BOUND.
245 * lisp.h (STRING_BYTES_BOUND): Renamed from STRING_BYTES_MAX.
246
247 * character.c (string_escape_byte8): Fix nbytes/nchars typo.
248
249 * alloc.c (Fmake_string): Check for out-of-range init.
250
12011-06-15 Stefan Monnier <monnier@iro.umontreal.ca> 2512011-06-15 Stefan Monnier <monnier@iro.umontreal.ca>
2 252
3 * eval.c (Fdefvaralias): Also mark the target as variable-special-p. 253 * eval.c (Fdefvaralias): Also mark the target as variable-special-p.