The protocol layer in src/shared/protocol.c uses module-global state for the active connection: io_read_fd, io_write_fd are static __thread (thread-local), but io_ssl is a plain static global. This means all threads in the same process share the same SSL* object, which is not thread-safe. Although the server currently forks per TCP connection, the multithreaded server path (server.c:84-111) and the multithreaded client pipeline could race on io_ssl.
Furthermore, the global state makes the protocol functions non-reentrant and harder to unit test.
Location
src/shared/protocol.c:13 — static SSL* io_ssl = NULL; should be static __thread SSL* io_ssl = NULL;.
src/shared/protocol.c:11-17 — all I/O state is global.
Suggested fix
Make io_ssl thread-local, or better:
Refactor send_n_data / receive_n_data to take an explicit I/O context struct (containing read fd, write fd, SSL pointer, and bandwidth limit) instead of using global state.
Severity
Medium
Category
bug, quality
This issue was automatically generated by the issue-creator agent.
## Description
The protocol layer in `src/shared/protocol.c` uses module-global state for the active connection: `io_read_fd`, `io_write_fd` are `static __thread` (thread-local), but `io_ssl` is a plain `static` global. This means all threads in the same process share the same `SSL*` object, which is not thread-safe. Although the server currently forks per TCP connection, the multithreaded server path (`server.c:84-111`) and the multithreaded client pipeline could race on `io_ssl`.
Furthermore, the global state makes the protocol functions non-reentrant and harder to unit test.
## Location
- `src/shared/protocol.c:13` — `static SSL* io_ssl = NULL;` should be `static __thread SSL* io_ssl = NULL;`.
- `src/shared/protocol.c:11-17` — all I/O state is global.
## Suggested fix
1. Make `io_ssl` thread-local, or better:
2. Refactor `send_n_data` / `receive_n_data` to take an explicit I/O context struct (containing read fd, write fd, SSL pointer, and bandwidth limit) instead of using global state.
## Severity
Medium
## Category
bug, quality
---
_This issue was automatically generated by the issue-creator agent._
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Description
The protocol layer in
src/shared/protocol.cuses module-global state for the active connection:io_read_fd,io_write_fdarestatic __thread(thread-local), butio_sslis a plainstaticglobal. This means all threads in the same process share the sameSSL*object, which is not thread-safe. Although the server currently forks per TCP connection, the multithreaded server path (server.c:84-111) and the multithreaded client pipeline could race onio_ssl.Furthermore, the global state makes the protocol functions non-reentrant and harder to unit test.
Location
src/shared/protocol.c:13—static SSL* io_ssl = NULL;should bestatic __thread SSL* io_ssl = NULL;.src/shared/protocol.c:11-17— all I/O state is global.Suggested fix
io_sslthread-local, or better:send_n_data/receive_n_datato take an explicit I/O context struct (containing read fd, write fd, SSL pointer, and bandwidth limit) instead of using global state.Severity
Medium
Category
bug, quality
This issue was automatically generated by the issue-creator agent.