NULL Pointer Dereference in cJSON_GetErrorPtr When cJSON_Parse Receives NULL Input
I maintainer di solito rispondono entro 12 giorni
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 64/100
Direzione di ricerca
Inizia in cJSON.c da cJSON_GetErrorPtr (righe 94–96) e cJSON_ParseWithLengthOpts (intorno alle righe 1153–1156), quindi segui il percorso di errore per l’input NULL e il modello documentato di segnalazione degli errori. Aggiungi una copertura di regressione per l’input segnalato e verifica con la configurazione esistente di test o fuzzing che la segnalazione degli errori non provochi più una dereferenziazione di NULL.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- C
- Stelle
- 13k
- Fork
- 3.5k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di DaveGamble/cJSON
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
DaveGamble/cJSON#1106 ·
I maintainer di solito rispondono entro 12 giorni
-
Undefined-Behavior in function cJSON_SetNumberHelperForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
DaveGamble/cJSON#1100 · 1 reazione ·
I maintainer di solito rispondono entro 12 giorni
-
CMake config files contain absolute install pathsForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
DaveGamble/cJSON#1094 · 9 commenti · 1 reazione ·
I maintainer di solito rispondono entro 12 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
DaveGamble/cJSON#1093 ·
I maintainer di solito rispondono entro 12 giorni
-
Use-after-free in cJSONUtils_ApplyPatches when a patch removes the patch arrayForse già presa @iliasabk l’ha presa 35 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
DaveGamble/cJSON#1082 ·
I maintainer di solito rispondono entro 12 giorni
Tutte le issue di DaveGamble/cJSON
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
containers/crun#2415 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
zephyrproject-rtos/zephyr#123423 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
dspromote: /etc/exports uses -alldirs on non-mount-point directories, so mountd exports nothingApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
nextbsd/nextbsd-userland#434 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno