Heap buffer overflow: createClient() indexes clients[fd] with no bound on fd
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 84/100
Línea de trabajo
Comienza en smallchat-server.c, en createClient(int fd), especialmente en los accesos a clients[c->fd] alrededor de las líneas 84-86, y luego inspecciona los bucles j <= maxclient. Compila con el comando de AddressSanitizer indicado y reproduce el problema con conexiones simultáneas; se considera terminado cuando los descriptores iguales o superiores a MAX_CLIENTS se gestionan sin accesos fuera de los límites y los bucles permanecen dentro del array clients.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
clients[MAX_CLIENTS] (smallchat-server.c) is indexed directly by the socket file descriptor with no bound check before the write. When the kernel hands accept() a descriptor fd >= 1000 (MAX_CLIENTS), createClient() writes past the end of the heap-allocated chatState struct.
// smallchat-server.c:84 createClient(int fd)
assert(Chat->clients[c->fd] == NULL); // OOB READ when fd >= 1000 (assert, compiled out via -DNDEBUG)
Chat->clients[c->fd] = c; // OOB WRITE when fd >= 1000 -- heap overflow
clients[MAX_CLIENTS] is the last member of chatState (offset 8016 bytes), so clients[1000] writes exactly 8 bytes past the object.
Reachability
The kernel allocates the lowest free descriptor to accept(). A client holding ~997 concurrent connections (routine for a chat server, well under typical ulimit -n) makes the next accept() return fd = 1000 -> createClient(1000) -> the OOB write. No special payload, no race -- just connection count.
Verification (AddressSanitizer)
Built with gcc -fsanitize=address -fno-omit-frame-pointer -g smallchat-server.c chatlib.c -o sc-asan, then opened 1050 concurrent connections.
Release build (-DNDEBUG, assert compiled out) -- OOB WRITE:
ERROR: AddressSanitizer: heap-buffer-overflow on address 0xffff7cc02050
WRITE of size 8 ...
#0 in createClient smallchat-server.c:86
#1 in main smallchat-server.c:189
0xffff7cc02050 is located 0 bytes to the right of 8016-byte region
SUMMARY: AddressSanitizer: heap-buffer-overflow smallchat-server.c:86 in createClient
Suggested fix
if (fd >= MAX_CLIENTS) {
close(fd);
return NULL;
}
and guard the j <= maxclient loops with j < MAX_CLIENTS.
This report was produced with AI assistance (Claude, Anthropic) performing source analysis and building/running the ASan proof-of-concept described above.
- Lenguaje dominante
- C
- Estrellas
- 7.5k
- Forks
- 845
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
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 antirez/smallchat
-
About Performance and TestingAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
-
How to compile on Windows.Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
How to use it? Read here.Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
Todos los issues de antirez/smallchat
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
chore(gateway): emit INFO budget reserved/settled logs for proactivity v2 (chip task_2855f4ec)Abiertobackend
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
BasedHardware/omi#20940 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Linux notifications: the default action's ' ' label shows as a blank button in xfce4-notifydAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
kovidgoyal/kitty#10625 ·
Los mantenedores suelen responder en 1 día
-
Feature Status: Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 1 día