diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-07 15:07:09 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-07 15:07:09 +0300 |
| commit | eb46afd5d10b0d2c95a90eade231d519415bdd80 (patch) | |
| tree | bb933dfbf69be582098190115f7405ce8b61e47b /yhttpd/src/reqp.h | |
| parent | 1f28ff5ac4a8a466113296d9510fe91f8cd13bc3 (diff) | |
yhttpd: fix malformed Content-Length crash and unchecked accept
Two residual stability bugs in yhttpd's own sock.cpp (ychat never had
them -- yhttpd's read_http request parser is structurally different
from ychat's), found while auditing for ychat engine-fix backports:
1. sock::read_http malformed Content-Length crash (a3908e1-class).
read_http matched the header on the 15-char prefix "Content-Length:"
(no space required) but then assumed the canonical
"Content-Length: <value>" form and substr'd from index 16. Two
reachable crash cases for any unauthenticated client:
- bare "Content-Length:" (15 chars): substr(16, len-16) had
pos > size -> std::out_of_range throw -> uncaught -> process crash.
- "Content-Length:\n" (16 chars, no value): the substring was
empty so the do/while digit scan read past the buffer (OOB read)
until a stray '\n' in adjacent memory.
Now guarded: require the space separator + a value before substr,
and bound the scan to the substring length. Verified in Docker:
both malformed cases close gracefully, a valid Content-Length: 0
POST still returns 200, server stays up.
2. sock::start unchecked accept(). The accept() return was used
unchecked; on failure (fd == -1, e.g. EMFILE/ENFILE under fd
exhaustion, EINTR) FD_SET(-1, &active_fd_set) is UB (bit-op on a
negative index) and the later _create_container(-1) would
read/write fd -1 (EBADF). Now bails with ACCPERR and continues on
any accept error (the accept-bail half of ychat's 1c36abe, which
the original yhttpd port only carried the size_t->socklen_t init of).
yhttpd is not deployed to the cluster (no Helm chart/ArgoCD app); this
is a build-and-verify-in-Docker project, so no deploy step. ycurses
shares no socket/template engine with ychat (it is a standalone curses
library demo) so nothing applies there.
Diffstat (limited to 'yhttpd/src/reqp.h')
0 files changed, 0 insertions, 0 deletions
