ruby-changes:62823
From: Alan <ko1@a...>
Date: Fri, 4 Sep 2020 06:42:26 +0900 (JST)
Subject: [ruby-changes:62823] d4585e7470 (master): Avoid potential for rb_raise() while crashing
https://git.ruby-lang.org/ruby.git/commit/?id=d4585e7470 From d4585e7470163c794025c2d56930c0e5a5fbae3c Mon Sep 17 00:00:00 2001 From: Alan Wu <XrXr@u...> Date: Thu, 3 Sep 2020 15:51:14 -0400 Subject: Avoid potential for rb_raise() while crashing rb_obj_raw_info is called while printing out crash messages and sometimes called during garbage collection. Calling rb_raise() in these situations is undesirable because it can start executing ensure blocks. diff --git a/gc.c b/gc.c index 535f526..99c79fe 100644 --- a/gc.c +++ b/gc.c @@ -11702,6 +11702,15 @@ rb_raw_iseq_info(char *buff, const int buff_size, const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/gc.c#L11702 bool rb_ractor_p(VALUE rv); +static int +str_len_no_raise(VALUE str) +{ + long len = RSTRING_LEN(str); + if (len < 0) return 0; + if (len > INT_MAX) return INT_MAX; + return (int)len; +} + const char * rb_raw_obj_info(char *buff, const int buff_size, VALUE obj) { @@ -11789,7 +11798,7 @@ rb_raw_obj_info(char *buff, const int buff_size, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L11798 } break; case T_STRING: { - APPENDF((BUFF_ARGS, "%.*s", RSTRING_LENINT(obj), RSTRING_PTR(obj))); + APPENDF((BUFF_ARGS, "%.*s", str_len_no_raise(obj), RSTRING_PTR(obj))); break; } case T_MOVED: { -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/