|
| 1 | +From 1e18e567de7b23797679817ba02a1f67995fe386 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Kanishk-Bansal <kbkanishk975@gmail.com> |
| 3 | +Date: Wed, 5 Mar 2025 08:19:33 +0000 |
| 4 | +Subject: [PATCH] CVE-2024-53427 |
| 5 | +Upstream Reference: https://github.com/jqlang/jq/commit/a09a4dfd55e6c24d04b35062ccfe4509748b1dd3 |
| 6 | +--- |
| 7 | + src/jv.c | 9 +++++++++ |
| 8 | + tests/jq.test | 13 ++++++++++--- |
| 9 | + tests/shtest | 5 ----- |
| 10 | + 3 files changed, 19 insertions(+), 8 deletions(-) |
| 11 | + |
| 12 | +diff --git a/src/jv.c b/src/jv.c |
| 13 | +index e23d8ec..34573b8 100644 |
| 14 | +--- a/src/jv.c |
| 15 | ++++ b/src/jv.c |
| 16 | +@@ -589,6 +589,15 @@ static jv jvp_literal_number_new(const char * literal) { |
| 17 | + jv_mem_free(n); |
| 18 | + return JV_INVALID; |
| 19 | + } |
| 20 | ++ if (decNumberIsNaN(&n->num_decimal)) { |
| 21 | ++ // Reject NaN with payload. |
| 22 | ++ if (n->num_decimal.digits > 1 || *n->num_decimal.lsu != 0) { |
| 23 | ++ jv_mem_free(n); |
| 24 | ++ return JV_INVALID; |
| 25 | ++ } |
| 26 | ++ jv_mem_free(n); |
| 27 | ++ return jv_number(NAN); |
| 28 | ++ } |
| 29 | + |
| 30 | + jv r = {JVP_FLAGS_NUMBER_LITERAL, 0, 0, JV_NUMBER_SIZE_INIT, {&n->refcnt}}; |
| 31 | + return r; |
| 32 | +diff --git a/tests/jq.test b/tests/jq.test |
| 33 | +index 7036df2..7011cf9 100644 |
| 34 | +--- a/tests/jq.test |
| 35 | ++++ b/tests/jq.test |
| 36 | +@@ -1938,10 +1938,17 @@ tojson | fromjson |
| 37 | + {"a":nan} |
| 38 | + {"a":null} |
| 39 | + |
| 40 | +-# also "nan with payload" #2985 |
| 41 | +-fromjson | isnan |
| 42 | +-"nan1234" |
| 43 | ++# NaN with payload is not parsed |
| 44 | ++.[] | try (fromjson | isnan) catch . |
| 45 | ++["NaN","-NaN","NaN1","NaN10","NaN100","NaN1000","NaN10000","NaN100000"] |
| 46 | ++true |
| 47 | + true |
| 48 | ++"Invalid numeric literal at EOF at line 1, column 4 (while parsing 'NaN1')" |
| 49 | ++"Invalid numeric literal at EOF at line 1, column 5 (while parsing 'NaN10')" |
| 50 | ++"Invalid numeric literal at EOF at line 1, column 6 (while parsing 'NaN100')" |
| 51 | ++"Invalid numeric literal at EOF at line 1, column 7 (while parsing 'NaN1000')" |
| 52 | ++"Invalid numeric literal at EOF at line 1, column 8 (while parsing 'NaN10000')" |
| 53 | ++"Invalid numeric literal at EOF at line 1, column 9 (while parsing 'NaN100000')" |
| 54 | + |
| 55 | + |
| 56 | + # calling input/0, or debug/0 in a test doesn't crash jq |
| 57 | +diff --git a/tests/shtest b/tests/shtest |
| 58 | +index 14aafbf..a471889 100755 |
| 59 | +--- a/tests/shtest |
| 60 | ++++ b/tests/shtest |
| 61 | +@@ -594,11 +594,6 @@ if ! x=$($JQ -n "1 # foo$cr + 2") || [ "$x" != 1 ]; then |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + |
| 65 | +-# CVE-2023-50268: No stack overflow comparing a nan with a large payload |
| 66 | +-$VALGRIND $Q $JQ '1 != .' <<\EOF >/dev/null |
| 67 | +-Nan4000 |
| 68 | +-EOF |
| 69 | +- |
| 70 | + # Allow passing the inline jq script before -- #2919 |
| 71 | + if ! r=$($JQ --args -rn -- '$ARGS.positional[0]' bar) || [ "$r" != bar ]; then |
| 72 | + echo "passing the inline script after -- didn't work" |
| 73 | +-- |
| 74 | +2.45.2 |
| 75 | + |
0 commit comments