summaryrefslogtreecommitdiffhomepage
path: root/src/class.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-04-01 14:13:06 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2019-04-01 14:13:06 +0900
commit2871d0cdc5e5ef952d27187b5488888bbd18c5b0 (patch)
tree8167e5b1914548d62bcb14ac32b0f1411fe39172 /src/class.c
parent6ec855a38e8116e4f0d04f188e948046b47af74f (diff)
downloadmruby-2871d0cdc5e5ef952d27187b5488888bbd18c5b0.tar.gz
mruby-2871d0cdc5e5ef952d27187b5488888bbd18c5b0.zip
Avoid keeping pointers from `mrb_sym2name_len()`; fix #4342
The addresses for packed inline symbols reference `mrb->symbuf` that could be overridden by the later call of `mrb_sym2name_len`. Since file names in call stack information are kept as symbols, keeping the address in the C structures could cause problems like #4342. This changes small incompatible changes in function prototypes: * `mrb_parser_get_filename`: return value changed to `mrb_sym`. * `mrb_debug_get_filename`: add `mrb_state*` as a first argument. * `mrb_debug_get_line`: ditto. I believe above functions are almost internal, and no third-party mrbgem use them.
Diffstat (limited to 'src/class.c')
-rw-r--r--src/class.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/class.c b/src/class.c
index 3354617bb..5c5ee9d17 100644
--- a/src/class.c
+++ b/src/class.c
@@ -484,15 +484,11 @@ mrb_define_method(mrb_state *mrb, struct RClass *c, const char *name, mrb_func_t
MRB_API void
mrb_notimplement(mrb_state *mrb)
{
- const char *str;
- mrb_int len;
mrb_callinfo *ci = mrb->c->ci;
if (ci->mid) {
- str = mrb_sym2name_len(mrb, ci->mid, &len);
- mrb_raisef(mrb, E_NOTIMP_ERROR,
- "%S() function is unimplemented on this machine",
- mrb_str_new_static(mrb, str, (size_t)len));
+ mrb_value str = mrb_sym2str(mrb, ci->mid);
+ mrb_raisef(mrb, E_NOTIMP_ERROR, "%S() function is unimplemented on this machine", str);
}
}
@@ -1686,11 +1682,7 @@ mrb_class_path(mrb_state *mrb, struct RClass *c)
}
else if (mrb_symbol_p(path)) {
/* toplevel class/module */
- const char *str;
- mrb_int len;
-
- str = mrb_sym2name_len(mrb, mrb_symbol(path), &len);
- return mrb_str_new(mrb, str, len);
+ return mrb_sym2str(mrb, mrb_symbol(path));
}
return mrb_str_dup(mrb, path);
}