Merge pull request #7232 from neheb/patch-11
[feed/packages.git] / utils / jq / patches / 001-stack-exhaustion.patch
1 From 2d38a12d686a5156d4e7afb1fed7851805590582 Mon Sep 17 00:00:00 2001
2 From: W-Mark Kubacki <wmark@hurrikane.de>
3 Date: Fri, 19 Aug 2016 19:50:39 +0200
4 Subject: [PATCH] Skip printing at MAX_DEPTH and deeper
5
6 This addresses #1136, and mitigates a stack exhaustion when printing
7 a very deeply nested term.
8 ---
9 src/jv_print.c | 8 +++++++-
10 1 file changed, 7 insertions(+), 1 deletion(-)
11
12 diff --git a/src/jv_print.c b/src/jv_print.c
13 index 5f4f234..cf6651b 100644
14 --- src/jv_print.c
15 +++ src/jv_print.c
16 @@ -13,6 +13,10 @@
17 #include "jv_dtoa.h"
18 #include "jv_unicode.h"
19
20 +#ifndef MAX_DEPTH
21 +#define MAX_DEPTH 256
22 +#endif
23 +
24 #define ESC "\033"
25 #define COL(c) (ESC "[" c "m")
26 #define COLRESET (ESC "[0m")
27 @@ -150,7 +154,9 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
28 }
29 }
30 }
31 - switch (jv_get_kind(x)) {
32 + if (indent > MAX_DEPTH) {
33 + put_str("<stripped: exceeds max depth>", F, S, flags & JV_PRINT_ISATTY);
34 + } else switch (jv_get_kind(x)) {
35 default:
36 case JV_KIND_INVALID:
37 if (flags & JV_PRINT_INVALID) {