diff options
author | W-Mark Kubacki <wmark@hurrikane.de> | 2016-08-19 19:50:39 +0200 |
---|---|---|
committer | Nico Williams <nico@cryptonector.com> | 2017-01-27 09:59:44 -0600 |
commit | 83e2cf607f3599d208b6b3129092fa7deb2e5292 (patch) | |
tree | ed96cc55867e21d501c23ab25fb078030e4ac077 | |
parent | 61b75639a76307329c6a26daff3ff00a57469185 (diff) |
Skip printing what's below a MAX_PRINT_DEPTH
This addresses #1136, and mitigates a stack exhaustion when printing
a very deeply nested term.
-rw-r--r-- | src/jv_print.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/jv_print.c b/src/jv_print.c index 5f4f234b..ce4a59af 100644 --- a/src/jv_print.c +++ b/src/jv_print.c @@ -13,6 +13,10 @@ #include "jv_dtoa.h" #include "jv_unicode.h" +#ifndef MAX_PRINT_DEPTH +#define MAX_PRINT_DEPTH (256) +#endif + #define ESC "\033" #define COL(c) (ESC "[" c "m") #define COLRESET (ESC "[0m") @@ -150,7 +154,9 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI } } } - switch (jv_get_kind(x)) { + if (indent > MAX_PRINT_DEPTH) { + put_str("<skipped: too deep>", F, S, flags & JV_PRINT_ISATTY); + } else switch (jv_get_kind(x)) { default: case JV_KIND_INVALID: if (flags & JV_PRINT_INVALID) { |