ruby-changes:64630
From: Nobuyoshi <ko1@a...>
Date: Sun, 27 Dec 2020 21:35:40 +0900 (JST)
Subject: [ruby-changes:64630] f6a080047e (master): Limit bactrace length from Exception#full_message
https://git.ruby-lang.org/ruby.git/commit/?id=f6a080047e From f6a080047e960e8b1821a97850830286ce9dee1c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 27 Dec 2020 20:50:15 +0900 Subject: Limit bactrace length from Exception#full_message diff --git a/eval_error.c b/eval_error.c index 841275e..98b8a22 100644 --- a/eval_error.c +++ b/eval_error.c @@ -228,7 +228,7 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA https://github.com/ruby/ruby/blob/trunk/eval_error.c#L228 } static void -print_backtrace(const VALUE eclass, const VALUE errat, const VALUE str, int reverse) +print_backtrace(const VALUE eclass, const VALUE errat, const VALUE str, int reverse, long backtrace_limit) { if (!NIL_P(errat)) { long i; @@ -253,8 +253,8 @@ print_backtrace(const VALUE eclass, const VALUE errat, const VALUE str, int reve https://github.com/ruby/ruby/blob/trunk/eval_error.c#L253 } // skip for explicit limit - if (rb_backtrace_length_limit >= 0 && len > rb_backtrace_length_limit + 2) { - skip_start = rb_backtrace_length_limit + 1; + if (backtrace_limit >= 0 && len > backtrace_limit + 2) { + skip_start = backtrace_limit + 1; skip_len = len - skip_start; } @@ -289,7 +289,7 @@ shown_cause_p(VALUE cause, VALUE *shown_causes) https://github.com/ruby/ruby/blob/trunk/eval_error.c#L289 } static void -show_cause(VALUE errinfo, VALUE str, VALUE highlight, VALUE reverse, VALUE *shown_causes) +show_cause(VALUE errinfo, VALUE str, VALUE highlight, VALUE reverse, long backtrace_limit, VALUE *shown_causes) { VALUE cause = rb_attr_get(errinfo, id_cause); if (!NIL_P(cause) && rb_obj_is_kind_of(cause, rb_eException) && @@ -298,14 +298,14 @@ show_cause(VALUE errinfo, VALUE str, VALUE highlight, VALUE reverse, VALUE *show https://github.com/ruby/ruby/blob/trunk/eval_error.c#L298 VALUE errat = rb_get_backtrace(cause); VALUE emesg = rb_get_message(cause); if (reverse) { - show_cause(cause, str, highlight, reverse, shown_causes); - print_backtrace(eclass, errat, str, TRUE); + show_cause(cause, str, highlight, reverse, backtrace_limit, shown_causes); + print_backtrace(eclass, errat, str, TRUE, backtrace_limit); print_errinfo(eclass, errat, emesg, str, highlight!=0); } else { print_errinfo(eclass, errat, emesg, str, highlight!=0); - print_backtrace(eclass, errat, str, FALSE); - show_cause(cause, str, highlight, reverse, shown_causes); + print_backtrace(eclass, errat, str, FALSE, backtrace_limit); + show_cause(cause, str, highlight, reverse, backtrace_limit, shown_causes); } } } @@ -315,6 +315,7 @@ rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlig https://github.com/ruby/ruby/blob/trunk/eval_error.c#L315 { volatile VALUE eclass; VALUE shown_causes = 0; + long backtrace_limit = rb_backtrace_length_limit; if (NIL_P(errinfo)) return; @@ -345,14 +346,14 @@ rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlig https://github.com/ruby/ruby/blob/trunk/eval_error.c#L346 len = p - (msg = buff); } write_warn2(str, msg, len); - show_cause(errinfo, str, highlight, reverse, &shown_causes); - print_backtrace(eclass, errat, str, TRUE); + show_cause(errinfo, str, highlight, reverse, backtrace_limit, &shown_causes); + print_backtrace(eclass, errat, str, TRUE, backtrace_limit); print_errinfo(eclass, errat, emesg, str, highlight!=0); } else { print_errinfo(eclass, errat, emesg, str, highlight!=0); - print_backtrace(eclass, errat, str, FALSE); - show_cause(errinfo, str, highlight, reverse, &shown_causes); + print_backtrace(eclass, errat, str, FALSE, backtrace_limit); + show_cause(errinfo, str, highlight, reverse, backtrace_limit, &shown_causes); } } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/