Skip to content

Commit 2ac1c5c

Browse files
[AUTO-CHERRYPICK] Patch jq for CVE-2024-53427 [High] - branch 3.0-dev (#12965)
Co-authored-by: Kanishk Bansal <103916909+Kanishk-Bansal@users.noreply.github.com>
1 parent 1acab3d commit 2ac1c5c

2 files changed

Lines changed: 81 additions & 2 deletions

File tree

SPECS/jq/CVE-2024-53427.patch

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+

SPECS/jq/jq.spec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
Summary: jq is a lightweight and flexible command-line JSON processor.
22
Name: jq
33
Version: 1.7.1
4-
Release: 1%{?dist}
4+
Release: 2%{?dist}
55
Group: Applications/System
66
Vendor: Microsoft Corporation
77
License: MIT
88
URL: https://jqlang.github.io/jq/
99
Source0: https://github.com/jqlang/jq/releases/download/%{name}-%{version}/%{name}-%{version}.tar.gz
10+
Patch0: CVE-2024-53427.patch
1011
Distribution: Azure Linux
1112
BuildRequires: bison
1213
BuildRequires: chrpath
@@ -29,7 +30,7 @@ Requires: %{name} = %{version}-%{release}
2930
Development files for jq
3031

3132
%prep
32-
%autosetup
33+
%autosetup -p1
3334

3435
%build
3536
%configure \
@@ -59,6 +60,9 @@ make check
5960
%{_includedir}/*
6061

6162
%changelog
63+
* Wed Mar 05 2025 Kanishk Bansal <kanbansal@microsoft.com> - 1.7.1-2
64+
- Patch CVE-2024-53427
65+
6266
* Fri Feb 02 2024 Thien Trung Vuong <tvuong@microsoft.com> - 1.7.1-1
6367
- Upgrade to version 1.7.1
6468

0 commit comments

Comments
 (0)