[Security] Stack Overflow via Uncontrolled Recursion in cJSONUtils_MergePatch
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với cJSONUtils_MergePatch và logic merge_tests trong tests/old_utils_tests.c, sau đó so sánh cách xử lý đệ quy của nó với hành vi của CJSON_NESTING_LIMIT được đề cập trong issue. Build với ENABLE_CJSON_UTILS và ENABLE_CJSON_TEST, tái hiện trường hợp 30,000 lớp và coi công việc đã hoàn tất khi patch lồng nhau không còn gây ra segmentation fault và hồi quy được bộ kiểm thử bao phủ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Clear and concise description of the bug:
A stack overflow vulnerability exists in the cJSON_Utils library due to uncontrolled recursion in the cJSONUtils_MergePatch function. When processing a JSON Merge Patch (RFC 7396) with deeply nested objects, the function recursively traverses the patch without any depth limit. This exhausts the system stack memory, leading to a segmentation fault and application crash (Denial of Service).
Steps to reproduce the bug :
To reproduce this with the existing test suite, modify tests/old_utils_tests.c to dynamically inject a deeply nested object:
1.Increase the size of the merges array and add a placeholder:
static const char *merges[16][3] = {
// ... existing tests ...
{"{}", "RECURSIVE_PLACEHOLDER", "{}"}
};
2.Modify the test loop in merge_tests to dynamically build a 30,000-layer object when the placeholder is encountered:
if (strcmp(merges[i][1], "RECURSIVE_PLACEHOLDER") == 0) {
int depth = 30000;
int d = 0;
patch = cJSON_CreateObject();
cJSON *current = patch;
for (d = 0; d < depth; d++) {
cJSON *next = cJSON_CreateObject();
cJSON_AddItemToObject(current, "a", next);
current = next;
}
}
3.Build and run the tests:
mkdir build
cd build
cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_CJSON_TEST=On -DCMAKE_BUILD_TYPE=Debug
make
./tests/old_utils_tests .
Expected behavior:
The function should either successfully process the nested structure or, more appropriately, return an error when a pre-defined recursion depth limit is exceeded, similar to the CJSON_NESTING_LIMIT enforced in the core library.
Observed behavior:
The program crashes with a Segmentation fault. GDB backtrace shows thousands of recursive calls to merge_patch (frames reaching over #13000), eventually exhausting the default stack size.
Platform(s) (compiler version, operating system version, CPU) on which the bug was observed:
OS: Ubuntu Linux 20.04+
Compiler: GCC
cJSON release(s), commit(s), or branch(es) in which the bug was observed :
cJSON(main branch)
- Ngôn ngữ chính
- C
- Star
- 13k
- Fork
- 3.5k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của DaveGamble/cJSON
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
DaveGamble/cJSON#1094 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
DaveGamble/cJSON#1093 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
DaveGamble/cJSON#1082 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
DaveGamble/cJSON#1081 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
DaveGamble/cJSON#1074 ·
Tất cả issue của DaveGamble/cJSON
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Status: Opened
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Issue-Bug Needs-Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
trezor/trezor-firmware#7997 ·
Maintainer thường phản hồi trong vòng 2 ngày