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

Heap buffer overflow: createClient() indexes clients[fd] with no bound on fd

Abierto Apto para principiantes
#59 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

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

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

  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 antirez/smallchat

Todos los issues de antirez/smallchat

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.