This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathjq-CVE-2016-4074.patch
55 lines (51 loc) · 1.61 KB
/
jq-CVE-2016-4074.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
diff --git a/src/jv_parse.c b/src/jv_parse.c
index 84245b86..51ad9f09 100644
--- a/jv_parse.c
+++ b/jv_parse.c
@@ -10,6 +10,10 @@
typedef const char* presult;
+#ifndef MAX_PARSING_DEPTH
+#define MAX_PARSING_DEPTH (256)
+#endif
+
#define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0)
#ifdef __GNUC__
#define pfunc __attribute__((warn_unused_result)) presult
@@ -147,11 +151,13 @@ static void push(struct jv_parser* p, jv v) {
static pfunc parse_token(struct jv_parser* p, char ch) {
switch (ch) {
case '[':
+ if (p->stackpos >= MAX_PARSING_DEPTH) return "Exceeds depth limit for parsing";
if (jv_is_valid(p->next)) return "Expected separator between values";
push(p, jv_array());
break;
case '{':
+ if (p->stackpos >= MAX_PARSING_DEPTH) return "Exceeds depth limit for parsing";
if (jv_is_valid(p->next)) return "Expected separator between values";
push(p, jv_object());
break;
diff --git a/src/jv_print.c b/src/jv_print.c
index 5f4f234b..ce4a59af 100644
--- a/jv_print.c
+++ b/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) {