From 711f06a562117c63b5b7b04f79d3c4a6b076b098 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 7 Sep 2021 07:35:35 +0900 Subject: eval.c: check length of the file name. It should be lexx than `UINT16_MAX`. If you don't check here, the parser would raise an exception. --- mrbgems/mruby-eval/src/eval.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'mrbgems/mruby-eval/src') diff --git a/mrbgems/mruby-eval/src/eval.c b/mrbgems/mruby-eval/src/eval.c index b10e0c7ce..a3c421f45 100644 --- a/mrbgems/mruby-eval/src/eval.c +++ b/mrbgems/mruby-eval/src/eval.c @@ -52,10 +52,19 @@ create_proc_from_string(mrb_state *mrb, const char *s, mrb_int len, mrb_value bi e = NULL; } + if (file) { + if (strlen(file) >= UINT16_MAX) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "filename too long"); + } + } + else { + file = "(eval)"; + } + cxt = mrbc_context_new(mrb); cxt->lineno = (uint16_t)line; - mrbc_filename(mrb, cxt, file ? file : "(eval)"); + mrbc_filename(mrb, cxt, file); cxt->capture_errors = TRUE; cxt->no_optimize = TRUE; cxt->upper = scope && MRB_PROC_CFUNC_P(scope) ? NULL : scope; -- cgit v1.2.3