NULL Pointer Dereference in cJSON_GetErrorPtr When cJSON_Parse Receives NULL Input
Los mantenedores suelen responder en 12 días
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 64/100
Línea de trabajo
Comienza en cJSON.c, en cJSON_GetErrorPtr (líneas 94–96) y cJSON_ParseWithLengthOpts (alrededor de las líneas 1153–1156); después, sigue la ruta de fallo para entradas NULL y el patrón documentado de notificación de errores. Añade cobertura de regresión para la entrada reportada y verifica con la configuración existente de pruebas o fuzzing que la notificación de errores ya no provoque una desreferencia de NULL.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
NULL Pointer Dereference in cJSON_GetErrorPtr When cJSON_Parse Receives NULL Input
Summary
A NULL pointer dereference vulnerability exists in function cJSON_GetErrorPtr at cJSON.c:94–96. When cJSON_Parse(NULL) is called, the function correctly returns NULL to indicate parse failure, but cJSON_GetErrorPtr() subsequently returns NULL instead of a valid error pointer. A caller following the documented error-reporting pattern will crash with a segmentation fault when dereferencing this NULL pointer.
Version
v1.7.19
Description
The root cause is in cJSON_ParseWithLengthOpts at cJSON.c:1156. When value == NULL, the code jumps to fail before setting global_error from the input buffer. The static variable global_error remains at its zero-initialized state {NULL, 0} (set at line 1153).cJSON_GetErrorPtr (line 94–96) computes:return (const char*) (global_error.json + global_error.position);// NULL + 0 = NULL
Steps to reproduce
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "cJSON.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
char *json_str = (char *)malloc(size + 1);
if (json_str == NULL) return 0;
memcpy(json_str, data, size);
json_str[size] = '\0';
cJSON *result = cJSON_ParseWithLength(json_str, size);
if (result != NULL) {
volatile char crash = *cJSON_GetErrorPtr();
(void)crash;
cJSON_Delete(result);
}
free(json_str);
return 0;
}
Reproduction Steps
$ https://github.com/DaveGamble/cJSON; cd cJSON.
$ clang-14 -I.. -g -fsanitize=fuzzer,address -o vuln3 vuln3.c path/to/cjson/cJSON.c path/to/cjson/cJSON_Utils.c -lm
$ ./vuln3 poc-3
==115411==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5fe79b9bd996 bp 0x7ffccf5df2a0 sp 0x7ffccf5df160 T0)
==115411==The signal is caused by a READ memory access.
==115411==Hint: address points to the zero page.
#0 0x5fe79b9bd996 in LLVMFuzzerTestOneInput /home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz.c:55:31
#1 0x5fe79b8e6393 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz+0x43393) (BuildId: 568bd0701503a6453788ada1dc42cb912068d8d3)
#2 0x5fe79b8d010f in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) (/home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz+0x2d10f) (BuildId: 568bd0701503a6453788ada1dc42cb912068d8d3)
#3 0x5fe79b8d5e66 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz+0x32e66) (BuildId: 568bd0701503a6453788ada1dc42cb912068d8d3)
#4 0x5fe79b8ffc82 in main (/home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz+0x5cc82) (BuildId: 568bd0701503a6453788ada1dc42cb912068d8d3)
#5 0x7766a9629d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#6 0x7766a9629e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#7 0x5fe79b8ca9d4 in _start (/home/ubuntu/Project/TRACE/database/cJSON/drivers/vuln3_null_geterrorptr_fuzz+0x279d4) (BuildId: 568bd0701503a6453788ada1dc42cb912068d8d3)
POC
https://github.com/sdnuhfiu/poc-yanzheng/poc-3
Impact
Potentially causing DoS
- Lenguaje dominante
- C
- Estrellas
- 13k
- Forks
- 3.5k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de DaveGamble/cJSON
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
DaveGamble/cJSON#1106 ·
Los mantenedores suelen responder en 12 días
-
Undefined-Behavior in function cJSON_SetNumberHelperPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
DaveGamble/cJSON#1100 · 1 reacción ·
Los mantenedores suelen responder en 12 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
DaveGamble/cJSON#1094 · 9 comentarios · 1 reacción ·
Los mantenedores suelen responder en 12 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
DaveGamble/cJSON#1093 ·
Los mantenedores suelen responder en 12 días
-
Use-after-free in cJSONUtils_ApplyPatches when a patch removes the patch arrayPosiblemente ocupada @iliasabk la tomó hace 32 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
DaveGamble/cJSON#1082 ·
Los mantenedores suelen responder en 12 días
Todos los issues de DaveGamble/cJSON
Issues similares
-
v9.6.0: CMake incorrectly enforces presence of libevdevPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
IoTSDK
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Azure/azure-iot-sdk-c#2776 ·
Los mantenedores suelen responder en 2 días
-
[Bug] Unhandled ValueError terminates watchdog thread when GISRC value contains multiple colonsAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
bug Component component: net
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
RT-Thread/rt-thread#11913 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
contiki-ng/contiki-ng#3289 ·
Los mantenedores suelen responder en 3 días