MIOBufferAccessor::reader_for(IOBufferReader *) dereferences a null reader and leaves VIOs pointing at freed readers

Abierto
#14,219 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
cpp
Área
api, backend

Línea de trabajo

Start with IOBuffer.cc around MIOBufferAccessor::reader_for(IOBufferReader *), then trace MIOBuffer::dealloc_reader() and the VIO get_reader()/get_writer() accessors. Check the cited CacheVC.cc call and the related guards in UnixNetVConnection::do_io_write() and PluginVC::do_io_write(). Done means null readers are handled safely and the reader lifetime and accessor ownership behavior are defined and covered.

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

Descripción

Bug IOBuffer

VIO::set_reader() is buffer.reader_for(reader), which is implemented at IOBuffer.cc#L1089-L1097:

if (entry == areader) {
  return;
}
mbuf  = areader->mbuf;
entry = areader;

There are two problems:

  1. Null reader. reader_for(nullptr) dereferences null unless the accessor's current reader is already null. Callers have to know this. UnixNetVConnection::do_io_write() and PluginVC::do_io_write() guard the call, and INKVConnInternal::do_io_write() crashed this way in #13395. CacheVC::do_io_write() still calls vio.set_reader(abuf) without a check (CacheVC.cc#L209), so a do_io_write(c, 0, nullptr) on a cache write VC that already has a reader would crash the same way.
  2. No back-pointer. Unlike reader_for(MIOBuffer *), which allocates the reader through alloc_accessor(this), this overload never sets areader->accessor. MIOBuffer::dealloc_reader() clears the accessor that a reader points back to (IOBuffer.cc#L1047-L1050). Without the back-pointer, freeing the reader or its buffer leaves the VIO holding dangling mbuf/entry pointers, which are reachable via VIO::get_reader()/get_writer() and TSVIOReaderGet()/TSVIOBufferGet(). This is harmless as long as nothing touches the VIO after its operation ends, but it is not enforced anywhere.

Suggested fix: make reader_for(nullptr) clear the accessor rather than dereference null. For the second problem, either register the accessor on the reader (the reader belongs to the VIO's producer, so this needs a defined owner) or document that the reader must outlive any use of the VIO.


generated with Claude Opus 5.5 by Josiah VanderZee

Lenguaje dominante
C++
Estrellas
2k
Forks
903
Merge medio
4 d 4 h
PR fusionados (30 d)
135

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 apache/trafficserver

Todos los issues de apache/trafficserver

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.