summaryrefslogtreecommitdiffhomepage
path: root/src/symbol.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/symbol.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/symbol.c')
-rw-r--r--src/symbol.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/symbol.c b/src/symbol.c
index 8ca03344c..96ca9dd17 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -520,7 +520,14 @@ mrb_sym2name(mrb_state *mrb, mrb_sym sym)
return name;
}
else {
- mrb_value str = mrb_str_dump(mrb, mrb_str_new_static(mrb, name, len));
+ mrb_value str;
+ if (sym&1) { /* inline symbol */
+ str = mrb_str_new(mrb, name, len);
+ }
+ else {
+ str = mrb_str_new_static(mrb, name, len);
+ }
+ str = mrb_str_dump(mrb, str);
return RSTRING_PTR(str);
}
}