Security/Bug: Null Pointer Dereference in cJSONUtils_strdup leads to Denial of Service (DoS)
Los mantenedores suelen responder en 12 días
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 68/100
Línea de trabajo
Comienza en cJSON_Utils.c, en cJSONUtils_strdup y en la ruta apply_patch mostrada en el trace de ASan; compara su gestión de NULL con cJSON_strdup en cJSON.c. Compila y ejecuta el PoC proporcionado para un parche malformado con AddressSanitizer. Se considera terminado cuando la entrada NULL ya no se desreferencia y los llamadores como apply_patch o detach_path gestionan de forma segura un resultado NULL.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- 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 28 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
-
[raylib] update to 6.2Abiertocategory:port-update
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 8 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
Los mantenedores suelen responder en 1 día
-
native-cpu: -Wreturn-type in skainet_row_threads.c:150 (worker fn has no return)Posiblemente ocupada @Doomguy-BFG9000 la tomó hoy. Abiertogood first issue size:xs skill:native
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
SKaiNET-developers/SKaiNET#1358 · 1 comentario ·
Los mantenedores suelen responder en 1 día