001-stack-exhaustion.patch 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. This addresses #1136, and mitigates a stack exhaustion when printing
  6. a very deeply nested term.
  7. ---
  8. src/jv_print.c | 8 +++++++-
  9. 1 file changed, 7 insertions(+), 1 deletion(-)
  10. diff --git a/src/jv_print.c b/src/jv_print.c
  11. index 5f4f234..cf6651b 100644
  12. --- src/jv_print.c
  13. +++ src/jv_print.c
  14. @@ -13,6 +13,10 @@
  15. #include "jv_dtoa.h"
  16. #include "jv_unicode.h"
  17. +#ifndef MAX_DEPTH
  18. +#define MAX_DEPTH 256
  19. +#endif
  20. +
  21. #define ESC "\033"
  22. #define COL(c) (ESC "[" c "m")
  23. #define COLRESET (ESC "[0m")
  24. @@ -150,7 +154,9 @@ static void jv_dump_term(struct dtoa_context* C, jv x, int flags, int indent, FI
  25. }
  26. }
  27. }
  28. - switch (jv_get_kind(x)) {
  29. + if (indent > MAX_DEPTH) {
  30. + put_str("<stripped: exceeds max depth>", F, S, flags & JV_PRINT_ISATTY);
  31. + } else switch (jv_get_kind(x)) {
  32. default:
  33. case JV_KIND_INVALID:
  34. if (flags & JV_PRINT_INVALID) {