Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[BUG] Use-After-Free (8-byte pointer write) in cJSON_Utils.c: sort_list() breaks the child->prev invariant

Abierto
#1,090 0 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 12 días

@nvnzno-a11y ya está trabajando en esto.

Desde el 22/9/2026.

  • #1091 de @nvnzno-a11y — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c
Área
security

Línea de trabajo

Start with sort_list() in cJSON_Utils.c around line 484, then read the child->prev handling in cJSON.c around lines 1761, 2001, 2052, and 2284. Build and run the supplied poc_min.c with the documented AddressSanitizer command. Done means the reproduction no longer reports the use-after-free after sorting, removing an interior member, and adding a member.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

I found a UAF caused by sort_list() in cJSON_Utils.c.It rebuilds an object's doubly linked list with mergesort but never restores cJSON's invariant child->prev == tail. After a sort, head->prev is either NULL or a live interior node. If that interior node is later removed (freed) and a member is then added to the same object, add_item_to_array() runs suffix_object(child->prev, item) → prev->next = item , writing 8-byte write into freed heap memory.

Branch : master 6d9f2443ab071f86e5d9b43025a40929ec41c46c.

Root cause

sort_list() (cJSON_Utils.c:484), merge loop:

if (result == NULL)
{
    /* start merged list with the smaller element */
    result_tail = smaller;
    result = smaller;      /* smaller->prev keeps its pre-sort value */
}

Only ->next and the prev of subsequently appended elements are maintained. The split path explicitly sets second->prev = NULL (cJSON_Utils.c:~528), so the stale value on the merged head is either NULL or a node that is still in the list.
cJSON depends on child->prev == tail. Established by the parser: head->prev = current_item (cJSON.c:1761) and consumed by add_item_to_array(): suffix_object(child->prev, item) (cJSON.c:2052) → prev->next = item (cJSON.c:2001).But the detach path only repairs it when the tail is removed (cJSON.c:2284), so deleting an interior node leaves child->prev dangling.

Reproduction (attached: poc_min.c)

three public API calls

gcc -g -O1 -fsanitize=address -I. cJSON.c cJSON_Utils.c poc_min.c -o poc_min -lm
./poc_min
POC

poc_min.c

asan-log.txt

Lenguaje dominante
C
Estrellas
13k
Forks
3.5k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de DaveGamble/cJSON

Todos los issues de DaveGamble/cJSON

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.