From 694c6b80a4eebd730229307c1953e10933346f40 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Sun, 6 Sep 2026 19:36:50 +0000 Subject: [PATCH] Fix ZString::operator[] to throw on out-of-range index instead of crashing Was an unchecked std::vector index (return list[index];). Any malformed/short line - a port scanner, a bot probing the port, or any client sending fewer colon-delimited fields than a given handler indexes via request[N] - reached this with no length check anywhere upstream, across every server built on this class. Depending on build flags that was either undefined behavior or, confirmed live (a real crash log from Zephora's game server), a hard process abort via libstdc++'s own vector bounds assertion: Assertion '__n < this->size()' failed. Throwing instead lets this be caught: every caller that dispatches a parsed request already wraps that dispatch in a try/catch (see CommandList::processRequest()), so a single malformed line is now cleanly rejected instead of taking down the entire server process for every connected player. --- ZString.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ZString.cpp b/ZString.cpp index 59f3467..0d3f460 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -370,6 +370,22 @@ namespace coreutils { } ZString &ZString::operator[](int index) { + // Previously an unchecked std::vector index - a single + // malformed/short line (a port scanner, a bot probing the port, + // or any client sending fewer colon-delimited fields than a + // given handler indexes) reaches every command handler across + // every server built on this class via request[N] with no + // length check first. Depending on build flags that was either + // undefined behavior or - confirmed live, crashing a real game + // server - a hard process abort (libstdc++'s own vector bounds + // assertion). Throwing here instead lets it be caught: every + // caller that dispatches a parsed request already wraps that + // dispatch in a try/catch (see CommandList::processRequest()), + // so this turns "one bad line takes down the whole server" into + // "that one line is cleanly rejected." + if (index < 0 || (size_t)index >= list.size()) + throw coreutils::Exception("ZString::operator[]: index " + std::to_string(index) + + " out of range (have " + std::to_string(list.size()) + ")"); return list[index]; }