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]; }