cJSON_Print trapped in an infinite loop when elements are added a certain way
Los mantenedores suelen responder en 12 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Empieza compilando y ejecutando el snippet mínimo en C para reproducir el bloqueo en cJSON_Print. Sigue el recorrido del array messages y de sus nodos system y message reutilizados; después, verifica que la impresión termina con JSON válido y que la secuencia de limpieza sigue siendo segura.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Here is a strange behavior of cJSON_Print. When the subtree it is transversing contains a node referenced by an ancestor node, it ends up in an infinite loop. The only way this can happen is if leaf nodes link back to their parents and cJSON_Print tries to transverse this path, resulting in a circular dep. Even this assumption doesn't hold up considering that when the order of placing objects message and system into the messages array is swapped (i.e., adding system before message), printing works perfectly.
Here is a minimal snippet to reproduce this behavior.
#include <stdio.h>
#include <stdlib.h>
#include "../cJSON/cJSON.h"
int main() {
cJSON *bin = cJSON_CreateArray();
cJSON *root = cJSON_CreateObject();
cJSON *system = cJSON_CreateObject();
cJSON *message = cJSON_CreateObject();
cJSON *messages = cJSON_CreateArray();
cJSON_AddItemToArray(bin, root);
cJSON_AddItemToArray(bin, system);
cJSON_AddItemToArray(bin, message);
cJSON_AddItemToArray(messages, message);
cJSON_AddItemToArray(messages, system);
cJSON_AddItemToObject(root, "messages", messages);
char *json_string = cJSON_Print(root);
printf("%s\n", json_string);
free(json_string);
cleanup:
cJSON_DetachItemFromArray(bin, 0);
cJSON_DetachItemFromArray(bin, 0);
cJSON_DetachItemFromArray(bin, 0);
cJSON_Delete(root);
cJSON_Delete(bin);
return 0;
}
- 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 33 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
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
valkey-io/valkey#4979 · 1 reacción ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
colbymchenry/codegraph#2770 ·
Los mantenedores suelen responder en 1 día
-
area/ysql kind/enhancement priority/medium status/awaiting-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
yugabyte/yugabyte-db#35578 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
test_announce_and_connect_via_dns binds a fixed port that other tests' nodes can be handedPosiblemente ocupada @ksedgwic la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
ElementsProject/lightning#9642 ·
Los mantenedores suelen responder en 2 días