diff options
| author | Andrea Corallo | 2021-02-16 21:41:36 +0100 |
|---|---|---|
| committer | Andrea Corallo | 2021-02-16 21:44:02 +0100 |
| commit | 543e6e664cf1f25fd7df04e75ffb582f5c7feab4 (patch) | |
| tree | 07f066876328d6c3f59541fdf9a0dbd8f800fa58 /src/comp.c | |
| parent | 31416495ad9b2c84473f72ad99e2adc87dd66e5a (diff) | |
| download | emacs-543e6e664cf1f25fd7df04e75ffb582f5c7feab4.tar.gz emacs-543e6e664cf1f25fd7df04e75ffb582f5c7feab4.zip | |
* Sanitize frame slot access in final
* src/comp.c (comp_t): Add 'frame_size' field.
(emit_mvar_lval): Add sanity check on frame element access.
(compile_function): Initialize 'comp.frame_size' and
'comp.frame_size'.
Diffstat (limited to 'src/comp.c')
| -rw-r--r-- | src/comp.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/comp.c b/src/comp.c index df770c650e6..0ab7ab600a4 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -560,6 +560,7 @@ typedef struct { | |||
| 560 | EMACS_INT func_speed; /* From comp-func speed slot. */ | 560 | EMACS_INT func_speed; /* From comp-func speed slot. */ |
| 561 | gcc_jit_block *block; /* Current basic block being compiled. */ | 561 | gcc_jit_block *block; /* Current basic block being compiled. */ |
| 562 | gcc_jit_lvalue *scratch; /* Used as scratch slot for some code sequence (switch). */ | 562 | gcc_jit_lvalue *scratch; /* Used as scratch slot for some code sequence (switch). */ |
| 563 | ptrdiff_t frame_size; /* Size of the following array in elements. */ | ||
| 563 | gcc_jit_lvalue **frame; /* Frame slot n -> gcc_jit_lvalue *. */ | 564 | gcc_jit_lvalue **frame; /* Frame slot n -> gcc_jit_lvalue *. */ |
| 564 | gcc_jit_rvalue *zero; | 565 | gcc_jit_rvalue *zero; |
| 565 | gcc_jit_rvalue *one; | 566 | gcc_jit_rvalue *one; |
| @@ -785,7 +786,9 @@ emit_mvar_lval (Lisp_Object mvar) | |||
| 785 | return comp.scratch; | 786 | return comp.scratch; |
| 786 | } | 787 | } |
| 787 | 788 | ||
| 788 | return comp.frame[XFIXNUM (mvar_slot)]; | 789 | EMACS_INT slot_n = XFIXNUM (mvar_slot); |
| 790 | eassert (slot_n < comp.frame_size); | ||
| 791 | return comp.frame[slot_n]; | ||
| 789 | } | 792 | } |
| 790 | 793 | ||
| 791 | static void | 794 | static void |
| @@ -3857,7 +3860,7 @@ static void | |||
| 3857 | compile_function (Lisp_Object func) | 3860 | compile_function (Lisp_Object func) |
| 3858 | { | 3861 | { |
| 3859 | USE_SAFE_ALLOCA; | 3862 | USE_SAFE_ALLOCA; |
| 3860 | EMACS_INT frame_size = XFIXNUM (CALL1I (comp-func-frame-size, func)); | 3863 | comp.frame_size = XFIXNUM (CALL1I (comp-func-frame-size, func)); |
| 3861 | 3864 | ||
| 3862 | comp.func = xmint_pointer (Fgethash (CALL1I (comp-func-c-name, func), | 3865 | comp.func = xmint_pointer (Fgethash (CALL1I (comp-func-c-name, func), |
| 3863 | comp.exported_funcs_h, Qnil)); | 3866 | comp.exported_funcs_h, Qnil)); |
| @@ -3871,7 +3874,7 @@ compile_function (Lisp_Object func) | |||
| 3871 | comp.func_relocs_ptr_type, | 3874 | comp.func_relocs_ptr_type, |
| 3872 | "freloc"); | 3875 | "freloc"); |
| 3873 | 3876 | ||
| 3874 | comp.frame = SAFE_ALLOCA (frame_size * sizeof (*comp.frame)); | 3877 | comp.frame = SAFE_ALLOCA (comp.frame_size * sizeof (*comp.frame)); |
| 3875 | if (comp.func_has_non_local || !comp.func_speed) | 3878 | if (comp.func_has_non_local || !comp.func_speed) |
| 3876 | { | 3879 | { |
| 3877 | /* FIXME: See bug#42360. */ | 3880 | /* FIXME: See bug#42360. */ |
| @@ -3882,10 +3885,10 @@ compile_function (Lisp_Object func) | |||
| 3882 | gcc_jit_context_new_array_type (comp.ctxt, | 3885 | gcc_jit_context_new_array_type (comp.ctxt, |
| 3883 | NULL, | 3886 | NULL, |
| 3884 | comp.lisp_obj_type, | 3887 | comp.lisp_obj_type, |
| 3885 | frame_size), | 3888 | comp.frame_size), |
| 3886 | "frame"); | 3889 | "frame"); |
| 3887 | 3890 | ||
| 3888 | for (ptrdiff_t i = 0; i < frame_size; ++i) | 3891 | for (ptrdiff_t i = 0; i < comp.frame_size; ++i) |
| 3889 | comp.frame[i] = | 3892 | comp.frame[i] = |
| 3890 | gcc_jit_context_new_array_access ( | 3893 | gcc_jit_context_new_array_access ( |
| 3891 | comp.ctxt, | 3894 | comp.ctxt, |
| @@ -3896,7 +3899,7 @@ compile_function (Lisp_Object func) | |||
| 3896 | i)); | 3899 | i)); |
| 3897 | } | 3900 | } |
| 3898 | else | 3901 | else |
| 3899 | for (ptrdiff_t i = 0; i < frame_size; ++i) | 3902 | for (ptrdiff_t i = 0; i < comp.frame_size; ++i) |
| 3900 | comp.frame[i] = | 3903 | comp.frame[i] = |
| 3901 | gcc_jit_function_new_local (comp.func, | 3904 | gcc_jit_function_new_local (comp.func, |
| 3902 | NULL, | 3905 | NULL, |