Commit Graph
68 Commits
Author SHA1 Message Date
Brad Arant 694c6b80a4 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.
2026-09-06 19:36:50 +00:00
Brad Arant 14697e2af2 Fix three real bugs found during a full ZString review
operator< computed end2 as valuex.getData() + valuex.getLength() - mixing
an absolute pointer (getData(), the buffer start) with a cursor-relative
length (getLength(), remaining-from-cursor). For any ZString with a
non-zero cursor offset this produces an end pointer short of the true
buffer end by exactly the amount already consumed, truncating the
comparison early. Fixed to use valuex.data + valuex.length (the true
end), matching how end1 was already computed for *this. operator<=,
>=, and > were separately broken (flagged by the codes own TODO
comment) - they compared via strncmp from data (ignoring cursor
entirely), inconsistent with operator< and with each other. Replaced
all three with derivations from the now-correct operator< (a <= b is
!(b < a), etc.) - guarantees trichotomy by construction instead of
three independently-written comparison loops.

substring(start, len): when the requested length overran the buffer,
computed newlen as endChar - end (the overrun amount) instead of
end - startChar (the actual remaining valid length) - backwards, and
stored into a char (max 127), silently wrapping for longer strings.
Fixed the formula and widened to size_t.

trimCRLF(): read *(data + length - 1) unconditionally, including when
length is already 0 - one byte before the buffer on an empty string.
Guarded both checks on length > 0.

Verified: full local compile (identical result to before - 13/20 clean,
same pre-existing StreamReader.h-blocked failures, nothing new broken);
a dedicated runtime test exercising all three fixes plus a trichotomy
check across multiple cursor offsets - all 13 assertions pass. Test
file not included in this commit.
2026-08-22 20:11:13 -07:00
Brad Arant ccfab5aecf Still working out parsing buffer stuff. 2025-12-17 17:07:14 -08:00
Brad Arant 829dc1a3c7 Fixed MString and MFile. 2025-12-04 16:40:11 -08:00
Brad Arant 11d6f00bfb Allow - to trigger the number check. 2025-11-25 15:28:31 -08:00
Brad Arant 5e6d162a05 added b64 encode/decode to MString. 2025-02-06 14:34:11 -08:00
Brad Arant c40e288a67 added trim operand function. 2025-01-16 13:38:35 -08:00
barant 5fd02a7a44 Fixed data type on comparisons. 2025-01-09 09:04:17 -08:00
barant cfd996fe5a cleanup for valgrind. 2024-12-23 13:00:22 -08:00
barant 0ebe8eaf5b cleanup for valgrind. 2024-12-23 11:15:53 -08:00
barant e5bfd7a840 fixed bug with substring on ZString. 2024-12-23 09:51:10 -08:00
barant 921854e455 fixed bug with asInteger on ZString. 2024-12-23 09:37:14 -08:00
barant 0d60cce8dc more serious work on JString. 2024-12-12 12:22:46 -08:00
brad Arant c644d8346f fixed asInteger math issue. 2024-11-27 15:26:21 -08:00
brad Arant 6ab31da76f fixed asInteger method to recognize cursor as asDouble does. 2024-11-27 15:09:39 -08:00
Brad Arant 76ba5414cd fixed moveBackToLineStart() method on ZString. 2024-11-26 10:37:39 -08:00
Brad Arant 2de5693e87 added moveBackToLineStart() method on ZString. 2024-11-26 10:33:31 -08:00
Brad Arant ab4da04de6 fixed cursor destruction on getLineNumberAtCursor() method to ZString. 2024-11-26 09:48:56 -08:00
Brad Arant 52d3985ffa added getLineNumberAtCursor() method to ZString. 2024-11-26 09:45:37 -08:00
brad Arant d6d16a1b7f renamed ifCRLF to trimCRLF to more accurately reflect the function. 2024-11-24 11:07:53 -08:00
Brad Arant 8f5dd52c6a changed getTokenExclude method to allow escaped characters. 2024-11-14 09:44:12 -08:00
Brad Arant c70f135710 Modified nextChar method to return character under cursor before incrementing cursor. 2024-11-13 08:54:09 -08:00
Brad Arant 01180021b4 Work on the IMFHeader and IMFMessage. 2024-11-11 15:58:58 -08:00
Brad Arant 2e8bb4a123 Created ifNextIgnoreCase method for ZString. 2024-11-05 15:44:51 -08:00
Brad Arant bf4ff3fdac Created destructive removeTrailingZeros() method on ZString. 2024-11-04 16:26:40 -08:00
Brad Arant f1337c682a Added ability for ifNextInclude and changed data type on isCaracter to ZString. 2024-10-31 15:48:13 -07:00
Brad Arant 3eb1f5954a Modified ifNext to only take the ZString parameter and let C++ do the conversions. 2024-10-30 08:36:30 -07:00
Brad Arant d0239074a4 Fixed erroneous operator== on ZString. 2024-10-16 11:37:18 -07:00
Brad Arant 34e2ca0566 Fixed NULL assignment to ZString. 2024-10-16 11:15:54 -07:00
Brad Arant 9d62a09140 Added >= and <= operators to ZString. 2024-09-30 16:50:17 -07:00
Brad Arant 439c0c9b32 Fixed bug in asDouble. 2024-09-26 14:17:10 -07:00
Brad Arant e2d20a0c2d Changed startsWithDouble to startsWithNumber. 2024-09-26 12:32:04 -07:00
Brad Arant 974a509767 Fixed bug in asDouble but changed its operation. Decimal only. 2024-09-26 12:19:34 -07:00
Brad Arant 75df8d0282 Made find() return -1 if not found. 2024-09-24 14:19:25 -07:00
Brad Arant d7ef47cd49 Add trim to ZString. 2024-09-24 11:14:58 -07:00
Brad Arant a1cc142a59 Completed cosing of substring. 2024-08-08 11:42:09 -07:00
Brad Arant 39fd88cad9 Added startsWithDouble() method on ZString. 2024-08-01 15:03:28 -07:00
Brad Arant 0db4be8a99 Fixed operator< on ZString. 2024-07-31 13:03:45 -07:00
Brad Arant ad74a9de85 Completed ZString::compare method. 2024-07-24 17:01:25 +00:00
Brad Arant dcf01ce555 initial compare coding. 2024-07-22 14:48:37 -07:00
Brad Arant d5bdfe8ca3 Added lineIsWhitespace function. 2024-07-11 13:53:53 -07:00
Brad Arant 1cfdc23a57 Added asDouble method to ZString. 2024-06-15 10:43:41 -07:00
Brad Arant beb3673241 Fixed == operator for empty string comparison. 2024-06-14 10:21:28 -07:00
Brad Arant b44a00862b Fixed leak in MString when assigning from another MString. 2023-10-07 18:04:23 -07:00
Brad Arant 8a9c1c3bd7 Worked on ZString, MString and JString 2023-10-05 17:57:01 -07:00
Brad Arant f39bdc98f6 jstring changes 2023-03-08 13:54:42 -08:00
Brad Arant 2a349c6ceb Many fixes for MString, ZString. 2022-08-23 09:30:56 -07:00
Brad Arant d0d5172afa Added substring capability to ZString. 2022-08-07 17:21:37 -07:00
Brad Arant d1c38dcfc8 Fix the operator != on ZString. 2022-08-05 00:28:58 +00:00
Brad Arant 963a0561e8 Continues ZString and MString adjustments. 2022-07-30 18:04:27 -07:00