diff options
| author | Chong Yidong | 2010-08-17 12:34:28 -0400 |
|---|---|---|
| committer | Chong Yidong | 2010-08-17 12:34:28 -0400 |
| commit | 3a7a912990d6583aabe7e1e807bb9c044f403b30 (patch) | |
| tree | 21e4af548652a3a6f33997fbe0336dc54cb7e2cb /src | |
| parent | 05a9766a14f990245816f9bbb37497c05ef3fd59 (diff) | |
| download | emacs-3a7a912990d6583aabe7e1e807bb9c044f403b30.tar.gz emacs-3a7a912990d6583aabe7e1e807bb9c044f403b30.zip | |
Avoid stack overflow in let, eval, and apply (Bug#6214).
* eval.c (Flet, Feval, Fapply, apply_lambda): Use SAFE_ALLOCA (Bug#6214).
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/eval.c | 31 |
2 files changed, 27 insertions, 9 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 2f011db3784..ce409d0fbbd 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2010-08-17 Chong Yidong <cyd@stupidchicken.com> | ||
| 2 | |||
| 3 | * eval.c (Flet, Feval, Fapply, apply_lambda): Use SAFE_ALLOCA | ||
| 4 | (Bug#6214). | ||
| 5 | |||
| 1 | 2010-08-14 Jan Djärv <jan.h.d@swipnet.se> | 6 | 2010-08-14 Jan Djärv <jan.h.d@swipnet.se> |
| 2 | 7 | ||
| 3 | * doc.c (Fsnarf_documentation): Set skip_file only if p[1] is S. | 8 | * doc.c (Fsnarf_documentation): Set skip_file only if p[1] is S. |
diff --git a/src/eval.c b/src/eval.c index 6609d3b5c8a..7bd27a0f144 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -1028,12 +1028,13 @@ usage: (let VARLIST BODY...) */) | |||
| 1028 | int count = SPECPDL_INDEX (); | 1028 | int count = SPECPDL_INDEX (); |
| 1029 | register int argnum; | 1029 | register int argnum; |
| 1030 | struct gcpro gcpro1, gcpro2; | 1030 | struct gcpro gcpro1, gcpro2; |
| 1031 | USE_SAFE_ALLOCA; | ||
| 1031 | 1032 | ||
| 1032 | varlist = Fcar (args); | 1033 | varlist = Fcar (args); |
| 1033 | 1034 | ||
| 1034 | /* Make space to hold the values to give the bound variables */ | 1035 | /* Make space to hold the values to give the bound variables */ |
| 1035 | elt = Flength (varlist); | 1036 | elt = Flength (varlist); |
| 1036 | temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object)); | 1037 | SAFE_ALLOCA (temps, Lisp_Object *, XFASTINT (elt) * sizeof (Lisp_Object)); |
| 1037 | 1038 | ||
| 1038 | /* Compute the values and store them in `temps' */ | 1039 | /* Compute the values and store them in `temps' */ |
| 1039 | 1040 | ||
| @@ -1066,6 +1067,7 @@ usage: (let VARLIST BODY...) */) | |||
| 1066 | } | 1067 | } |
| 1067 | 1068 | ||
| 1068 | elt = Fprogn (Fcdr (args)); | 1069 | elt = Fprogn (Fcdr (args)); |
| 1070 | SAFE_FREE (); | ||
| 1069 | return unbind_to (count, elt); | 1071 | return unbind_to (count, elt); |
| 1070 | } | 1072 | } |
| 1071 | 1073 | ||
| @@ -2299,8 +2301,10 @@ DEFUN ("eval", Feval, Seval, 1, 1, 0, | |||
| 2299 | /* Pass a vector of evaluated arguments */ | 2301 | /* Pass a vector of evaluated arguments */ |
| 2300 | Lisp_Object *vals; | 2302 | Lisp_Object *vals; |
| 2301 | register int argnum = 0; | 2303 | register int argnum = 0; |
| 2304 | USE_SAFE_ALLOCA; | ||
| 2302 | 2305 | ||
| 2303 | vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object)); | 2306 | SAFE_ALLOCA (vals, Lisp_Object *, |
| 2307 | XINT (numargs) * sizeof (Lisp_Object)); | ||
| 2304 | 2308 | ||
| 2305 | GCPRO3 (args_left, fun, fun); | 2309 | GCPRO3 (args_left, fun, fun); |
| 2306 | gcpro3.var = vals; | 2310 | gcpro3.var = vals; |
| @@ -2318,6 +2322,7 @@ DEFUN ("eval", Feval, Seval, 1, 1, 0, | |||
| 2318 | 2322 | ||
| 2319 | val = (*XSUBR (fun)->function) (XINT (numargs), vals); | 2323 | val = (*XSUBR (fun)->function) (XINT (numargs), vals); |
| 2320 | UNGCPRO; | 2324 | UNGCPRO; |
| 2325 | SAFE_FREE (); | ||
| 2321 | goto done; | 2326 | goto done; |
| 2322 | } | 2327 | } |
| 2323 | 2328 | ||
| @@ -2430,8 +2435,9 @@ usage: (apply FUNCTION &rest ARGUMENTS) */) | |||
| 2430 | register int i, numargs; | 2435 | register int i, numargs; |
| 2431 | register Lisp_Object spread_arg; | 2436 | register Lisp_Object spread_arg; |
| 2432 | register Lisp_Object *funcall_args; | 2437 | register Lisp_Object *funcall_args; |
| 2433 | Lisp_Object fun; | 2438 | Lisp_Object fun, retval; |
| 2434 | struct gcpro gcpro1; | 2439 | struct gcpro gcpro1; |
| 2440 | USE_SAFE_ALLOCA; | ||
| 2435 | 2441 | ||
| 2436 | fun = args [0]; | 2442 | fun = args [0]; |
| 2437 | funcall_args = 0; | 2443 | funcall_args = 0; |
| @@ -2470,8 +2476,8 @@ usage: (apply FUNCTION &rest ARGUMENTS) */) | |||
| 2470 | { | 2476 | { |
| 2471 | /* Avoid making funcall cons up a yet another new vector of arguments | 2477 | /* Avoid making funcall cons up a yet another new vector of arguments |
| 2472 | by explicitly supplying nil's for optional values */ | 2478 | by explicitly supplying nil's for optional values */ |
| 2473 | funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args) | 2479 | SAFE_ALLOCA (funcall_args, Lisp_Object *, |
| 2474 | * sizeof (Lisp_Object)); | 2480 | (1 + XSUBR (fun)->max_args) * sizeof (Lisp_Object)); |
| 2475 | for (i = numargs; i < XSUBR (fun)->max_args;) | 2481 | for (i = numargs; i < XSUBR (fun)->max_args;) |
| 2476 | funcall_args[++i] = Qnil; | 2482 | funcall_args[++i] = Qnil; |
| 2477 | GCPRO1 (*funcall_args); | 2483 | GCPRO1 (*funcall_args); |
| @@ -2483,8 +2489,8 @@ usage: (apply FUNCTION &rest ARGUMENTS) */) | |||
| 2483 | function itself as well as its arguments. */ | 2489 | function itself as well as its arguments. */ |
| 2484 | if (!funcall_args) | 2490 | if (!funcall_args) |
| 2485 | { | 2491 | { |
| 2486 | funcall_args = (Lisp_Object *) alloca ((1 + numargs) | 2492 | SAFE_ALLOCA (funcall_args, Lisp_Object *, |
| 2487 | * sizeof (Lisp_Object)); | 2493 | (1 + numargs) * sizeof (Lisp_Object)); |
| 2488 | GCPRO1 (*funcall_args); | 2494 | GCPRO1 (*funcall_args); |
| 2489 | gcpro1.nvars = 1 + numargs; | 2495 | gcpro1.nvars = 1 + numargs; |
| 2490 | } | 2496 | } |
| @@ -2500,7 +2506,11 @@ usage: (apply FUNCTION &rest ARGUMENTS) */) | |||
| 2500 | } | 2506 | } |
| 2501 | 2507 | ||
| 2502 | /* By convention, the caller needs to gcpro Ffuncall's args. */ | 2508 | /* By convention, the caller needs to gcpro Ffuncall's args. */ |
| 2503 | RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args)); | 2509 | retval = Ffuncall (gcpro1.nvars, funcall_args); |
| 2510 | UNGCPRO; | ||
| 2511 | SAFE_FREE (); | ||
| 2512 | |||
| 2513 | return retval; | ||
| 2504 | } | 2514 | } |
| 2505 | 2515 | ||
| 2506 | /* Run hook variables in various ways. */ | 2516 | /* Run hook variables in various ways. */ |
| @@ -3108,9 +3118,11 @@ apply_lambda (fun, args, eval_flag) | |||
| 3108 | struct gcpro gcpro1, gcpro2, gcpro3; | 3118 | struct gcpro gcpro1, gcpro2, gcpro3; |
| 3109 | register int i; | 3119 | register int i; |
| 3110 | register Lisp_Object tem; | 3120 | register Lisp_Object tem; |
| 3121 | USE_SAFE_ALLOCA; | ||
| 3111 | 3122 | ||
| 3112 | numargs = Flength (args); | 3123 | numargs = Flength (args); |
| 3113 | arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object)); | 3124 | SAFE_ALLOCA (arg_vector, Lisp_Object *, |
| 3125 | XINT (numargs) * sizeof (Lisp_Object)); | ||
| 3114 | args_left = args; | 3126 | args_left = args; |
| 3115 | 3127 | ||
| 3116 | GCPRO3 (*arg_vector, args_left, fun); | 3128 | GCPRO3 (*arg_vector, args_left, fun); |
| @@ -3139,6 +3151,7 @@ apply_lambda (fun, args, eval_flag) | |||
| 3139 | tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil))); | 3151 | tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil))); |
| 3140 | /* Don't do it again when we return to eval. */ | 3152 | /* Don't do it again when we return to eval. */ |
| 3141 | backtrace_list->debug_on_exit = 0; | 3153 | backtrace_list->debug_on_exit = 0; |
| 3154 | SAFE_FREE (); | ||
| 3142 | return tem; | 3155 | return tem; |
| 3143 | } | 3156 | } |
| 3144 | 3157 | ||