diff options
| author | Paul Eggert | 2014-09-07 00:04:01 -0700 |
|---|---|---|
| committer | Paul Eggert | 2014-09-07 00:04:01 -0700 |
| commit | b3bf18b3b87ac8f00857b8bfc3f2c74cf0e2fb7d (patch) | |
| tree | cf138164e4f8887394f52cb22da594d1713da316 /src/fontset.c | |
| parent | 930fb80f9e2815e599eb1de699668d42e305fa21 (diff) | |
| download | emacs-b3bf18b3b87ac8f00857b8bfc3f2c74cf0e2fb7d.tar.gz emacs-b3bf18b3b87ac8f00857b8bfc3f2c74cf0e2fb7d.zip | |
Use SAFE_ALLOCA etc. to avoid unbounded stack allocation.
This follows up on the recent thread in emacs-devel on alloca; see:
http://lists.gnu.org/archive/html/emacs-devel/2014-09/msg00042.html
This patch also cleans up alloca-related glitches noted while
examining the code looking for unbounded alloca.
* alloc.c (listn):
* callproc.c (init_callproc):
Rewrite to avoid need for alloca.
* buffer.c (mouse_face_overlay_overlaps)
(report_overlay_modification):
* buffer.h (GET_OVERLAYS_AT):
* coding.c (make_subsidiaries):
* doc.c (Fsnarf_documentation):
* editfns.c (Fuser_full_name):
* fileio.c (Ffile_name_directory, Fexpand_file_name)
(search_embedded_absfilename, Fsubstitute_in_file_name):
* fns.c (Fmake_hash_table):
* font.c (font_vconcat_entity_vectors, font_update_drivers):
* fontset.c (fontset_pattern_regexp, Ffontset_info):
* frame.c (Fmake_terminal_frame, x_set_frame_parameters)
(xrdb_get_resource, x_get_resource_string):
* ftfont.c (ftfont_get_charset, ftfont_check_otf, ftfont_drive_otf):
* ftxfont.c (ftxfont_draw):
* image.c (xbm_load, xpm_load, jpeg_load_body):
* keyboard.c (echo_add_key, menu_bar_items, tool_bar_items):
* keymap.c (Fdescribe_buffer_bindings, describe_map):
* lread.c (openp):
* menu.c (digest_single_submenu, find_and_call_menu_selection)
(find_and_return_menu_selection):
* print.c (PRINTFINISH):
* process.c (Fformat_network_address):
* scroll.c (do_scrolling, do_direct_scrolling, scrolling_1):
* search.c (search_buffer, Fmatch_data, Fregexp_quote):
* sound.c (wav_play, au_play):
* syntax.c (skip_chars):
* term.c (tty_menu_activate, tty_menu_show):
* textprop.c (get_char_property_and_overlay):
* window.c (Fset_window_configuration):
* xdisp.c (safe__call, next_overlay_change, vmessage)
(compute_overhangs_and_x, draw_glyphs, note_mouse_highlight):
* xfaces.c (face_at_buffer_position):
* xmenu.c (x_menu_show):
Use SAFE_ALLOCA etc. instead of plain alloca, since the
allocation size isn't bounded.
* callint.c (Fcall_interactively): Redo memory_full check
so that it can be done at compile-time on some platforms.
* coding.c (MAX_LOOKUP_MAX): New constant.
(get_translation_table): Use it.
* callproc.c (call_process): Use SAFE_NALLOCA instead of
SAFE_ALLOCA, to catch integer overflows on size calculation.
(exec_failed) [!DOS_NT]: New function.
(child_setup) [!DOS_NT]: Use it.
* editfns.c (Ftranspose_regions):
Hoist USE_SAFE_ALLOC + SAFE_FREE out of 'if'.
* editfns.c (check_translation):
Allocate larger buffers on the heap.
* eval.c (internal_lisp_condition_case):
Check for MAX_ALLOCA overflow.
* fns.c (sort_vector): Use SAFE_ALLOCA_LISP rather than Fmake_vector.
(Fbase64_encode_region, Fbase64_decode_region):
Avoid unnecessary calls to SAFE_FREE before 'error'.
* buffer.c (mouse_face_overlay_overlaps):
* editfns.c (Fget_pos_property, check_translation):
* eval.c (Ffuncall):
* font.c (font_unparse_xlfd, font_find_for_lface):
* ftfont.c (ftfont_drive_otf):
* keyboard.c (echo_add_key, read_decoded_event_from_main_queue)
(menu_bar_items, tool_bar_items):
* sound.c (Fplay_sound_internal):
* xdisp.c (load_overlay_strings, dump_glyph_row):
Use an ordinary auto buffer rather than alloca, since the
allocation size is fixed and small.
* ftfont.c: Include <c-strcase.h>.
(matching_prefix): New function.
(get_adstyle_property): Use it, to avoid need for alloca.
* keyboard.c (echo_add_key):
* keymap.c (describe_map): Use ptrdiff_t, not int.
* keyboard.c (echo_add_key): Prefer sizeof to strlen.
* keymap.c (Fdescribe_buffer_bindings): Use SBYTES, not SCHARS,
when counting bytes.
* lisp.h (xlispstrdupa): Remove, replacing with ...
(SAFE_ALLOCA_STRING): ... new macro with different API.
This fixes a portability problem, namely, alloca result
passed to another function. All uses changed.
(SAFE_ALLOCA, SAFE_ALLOCA_LISP): Check for MAX_ALLOCA,
not MAX_ALLOCA - 1.
* regex.c (REGEX_USE_SAFE_ALLOCA, REGEX_SAFE_FREE)
(REGEX_ALLOCATE): New macros.
(REGEX_REALLOCATE, REGEX_ALLOCATE_STACK, REGEX_REALLOCATE_STACK)
(REGEX_FREE_STACK, FREE_VARIABLES, re_match_2_internal):
Use them.
* xdisp.c (message3): Use SAFE_ALLOCA_STRING rather than doing it
by hand.
(decode_mode_spec_coding): Store directly into buf rather than
into an alloca temporary and copying the temporary to the buf.
Fixes: debbugs:18410
Diffstat (limited to 'src/fontset.c')
| -rw-r--r-- | src/fontset.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/fontset.c b/src/fontset.c index d99a3bcb7ef..8ff53a1d3a4 100644 --- a/src/fontset.c +++ b/src/fontset.c | |||
| @@ -1079,10 +1079,11 @@ fontset_pattern_regexp (Lisp_Object pattern) | |||
| 1079 | /* If PATTERN is not full XLFD we convert "*" to ".*". Otherwise | 1079 | /* If PATTERN is not full XLFD we convert "*" to ".*". Otherwise |
| 1080 | we convert "*" to "[^-]*" which is much faster in regular | 1080 | we convert "*" to "[^-]*" which is much faster in regular |
| 1081 | expression matching. */ | 1081 | expression matching. */ |
| 1082 | if (ndashes < 14) | 1082 | ptrdiff_t regexsize = (SBYTES (pattern) |
| 1083 | p1 = regex = alloca (SBYTES (pattern) + 2 * nstars + 2 * nescs + 1); | 1083 | + (ndashes < 14 ? 2 : 5) * nstars |
| 1084 | else | 1084 | + 2 * nescs + 1); |
| 1085 | p1 = regex = alloca (SBYTES (pattern) + 5 * nstars + 2 * nescs + 1); | 1085 | USE_SAFE_ALLOCA; |
| 1086 | p1 = regex = SAFE_ALLOCA (regexsize); | ||
| 1086 | 1087 | ||
| 1087 | *p1++ = '^'; | 1088 | *p1++ = '^'; |
| 1088 | for (p0 = SDATA (pattern); *p0; p0++) | 1089 | for (p0 = SDATA (pattern); *p0; p0++) |
| @@ -1110,6 +1111,7 @@ fontset_pattern_regexp (Lisp_Object pattern) | |||
| 1110 | 1111 | ||
| 1111 | Vcached_fontset_data = Fcons (build_string (SSDATA (pattern)), | 1112 | Vcached_fontset_data = Fcons (build_string (SSDATA (pattern)), |
| 1112 | build_string ((char *) regex)); | 1113 | build_string ((char *) regex)); |
| 1114 | SAFE_FREE (); | ||
| 1113 | } | 1115 | } |
| 1114 | 1116 | ||
| 1115 | return CACHED_FONTSET_REGEX; | 1117 | return CACHED_FONTSET_REGEX; |
| @@ -1892,7 +1894,9 @@ format is the same as above. */) | |||
| 1892 | 1894 | ||
| 1893 | /* Recode fontsets realized on FRAME from the base fontset FONTSET | 1895 | /* Recode fontsets realized on FRAME from the base fontset FONTSET |
| 1894 | in the table `realized'. */ | 1896 | in the table `realized'. */ |
| 1895 | realized[0] = alloca (word_size * ASIZE (Vfontset_table)); | 1897 | USE_SAFE_ALLOCA; |
| 1898 | SAFE_ALLOCA_LISP (realized[0], 2 * ASIZE (Vfontset_table)); | ||
| 1899 | realized[1] = realized[0] + ASIZE (Vfontset_table); | ||
| 1896 | for (i = j = 0; i < ASIZE (Vfontset_table); i++) | 1900 | for (i = j = 0; i < ASIZE (Vfontset_table); i++) |
| 1897 | { | 1901 | { |
| 1898 | elt = FONTSET_FROM_ID (i); | 1902 | elt = FONTSET_FROM_ID (i); |
| @@ -1903,7 +1907,6 @@ format is the same as above. */) | |||
| 1903 | } | 1907 | } |
| 1904 | realized[0][j] = Qnil; | 1908 | realized[0][j] = Qnil; |
| 1905 | 1909 | ||
| 1906 | realized[1] = alloca (word_size * ASIZE (Vfontset_table)); | ||
| 1907 | for (i = j = 0; ! NILP (realized[0][i]); i++) | 1910 | for (i = j = 0; ! NILP (realized[0][i]); i++) |
| 1908 | { | 1911 | { |
| 1909 | elt = FONTSET_DEFAULT (realized[0][i]); | 1912 | elt = FONTSET_DEFAULT (realized[0][i]); |
| @@ -1995,6 +1998,7 @@ format is the same as above. */) | |||
| 1995 | break; | 1998 | break; |
| 1996 | } | 1999 | } |
| 1997 | 2000 | ||
| 2001 | SAFE_FREE (); | ||
| 1998 | return tables[0]; | 2002 | return tables[0]; |
| 1999 | } | 2003 | } |
| 2000 | 2004 | ||