summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-pack/src/pack.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-09-19 20:53:32 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-09-19 22:01:59 +0900
commitc09d250ca148c0efc0167d55885bd20da87b43f7 (patch)
treedd1ed14792a5bf45a79d44167556b4206c9698d8 /mrbgems/mruby-pack/src/pack.c
parent8b43754644660c9dcdc6b8b18a1917f01e77479e (diff)
downloadmruby-c09d250ca148c0efc0167d55885bd20da87b43f7.tar.gz
mruby-c09d250ca148c0efc0167d55885bd20da87b43f7.zip
Remove implicit conversion using `to_int` method.
The ISO standard does not include implicit type conversion using `to_int`. This implicit conversion often causes vulnerability. There will be no more attacks like #4120. In addition, we have added internal convenience method `__to_int` which does type check and conversion (from floats).
Diffstat (limited to 'mrbgems/mruby-pack/src/pack.c')
-rw-r--r--mrbgems/mruby-pack/src/pack.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/mrbgems/mruby-pack/src/pack.c b/mrbgems/mruby-pack/src/pack.c
index f970d9339..0fa8c90bd 100644
--- a/mrbgems/mruby-pack/src/pack.c
+++ b/mrbgems/mruby-pack/src/pack.c
@@ -1124,14 +1124,16 @@ mrb_pack_pack(mrb_state *mrb, mrb_value ary)
o = mrb_ary_ref(mrb, ary, aidx);
if (type == PACK_TYPE_INTEGER) {
o = mrb_to_int(mrb, o);
+ }
#ifndef MRB_WITHOUT_FLOAT
- } else if (type == PACK_TYPE_FLOAT) {
+ else if (type == PACK_TYPE_FLOAT) {
if (!mrb_float_p(o)) {
mrb_float f = mrb_to_flo(mrb, o);
o = mrb_float_value(mrb, f);
}
+ }
#endif
- } else if (type == PACK_TYPE_STRING) {
+ else if (type == PACK_TYPE_STRING) {
if (!mrb_string_p(o)) {
mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %S into String", mrb_class_path(mrb, mrb_obj_class(mrb, o)));
}