100 Commits
Author SHA1 Message Date
Brad ArantandClaude Sonnet 5 2cea81c996 Fix heap corruption from unvalidated Content-Length causing repeated production crashes
HTTPRequest::parse() passed the parsed Content-Length straight into a
bounds check and a buffer read with no validation. ZString::asInteger()
accumulates digits into a plain 32-bit int with no overflow check, so a
request claiming an absurd Content-Length (confirmed live: a classic
SSTP vulnerability-scanner probe sending "Content-Length:
18446744073709551615") silently overflowed to -1. That negative value
passed the "buffer.getLength() < contentLength" guard for any real
buffer size, then got used as a length in ZString(cursor,
contentLength) - reinterpreted as an enormous size_t, this read far
past the real buffer and corrupted the heap, crashing the process
(sometimes immediately, sometimes much later in an unrelated objects
destructor) every time this scanner traffic reached it.

This single bug was silently crash-looping barant.com (3x in ~30
hours) and the ClockPlanet server (3x over the same window) before
systemds auto-restart each time masked the outage - confirmed via
live core dump analysis (gdb bt full showing double free or
corruption (out) inside MString::~MString, called from
HTTPRequest::parse, with contentLength = -1 in the frame). Fixed by
rejecting a negative Content-Length immediately, before it is ever
used - the same throw-on-malformed-input pattern this function already
uses for a bad request line and unsupported Transfer-Encoding.

Verified live against the exact attack string on both barant.com and
the ClockPlanet server: the connection is now cleanly rejected and the
service stays up with no restart.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-10 07:39:46 +00:00
Brad ArantandClaude Sonnet 5 05374bdb15 Fix MString::read() infinite retry loop, HTTPRequest parser fd leak, Log deadlock, log rotation symlink handling, and JString bounds checks
- MString::read() now gives up after repeated I/O errors instead of
  looping forever and crashing via realloc() failure (root cause of a
  recurring barant.com production crash).
- HTTPRequest::parse() no longer leaks lineParser/headerParser on a
  malformed request.
- Log gained size-based rotation (config-driven) and a non-static-mutex
  fix; a separate fix stopped rotation from destroying the logs symlink
  on its first trigger.
- File.cpp: symlink-preserving rotation support.
- JString: fixed an array-index out-of-bounds and a setString issue.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-06 17:38:14 +00:00
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 a0cef8077d Implement MString(void*) - declared but never defined
Invisible until this session's ServerCore tls/master merge brought
Subscription/SubscriptionManager (which calls it) into the same
dependency chain as a real executable for the first time - a static
library archive (ar) never checks for unresolved symbols, only the
final link of a real binary does, so this went unnoticed for however
long it sat declared-only in MString.h. Stores the raw pointer value
as the string bytes (pointer-identity comparison, matching how void*
aliases are compared everywhere else in this codebase) rather than
dereferencing it, since some callers pass arbitrary non-string
pointers through this constructor.
2026-09-06 14:12:14 +00:00
Brad Arant 29db853706 Fix CGIFormData to actually store file-upload part content
File-upload parts (Content-Disposition with filename=) were
unconditionally flagged currentSkip and discarded at PART_BOUNDARY,
so every <field type="file"> upload site (track audio, presets,
project icons) only ever received an empty value via $[fieldname],
never the real uploaded bytes.
2026-09-06 04:04:48 +00:00
Brad Arant 78c45d378c Fix File stat-before-open crash risk, JSON string-quoting bug, and MString buffer overflow
- File: stat() only after a successful open() (previously ran first with
  its result ignored, feeding a missing file's garbage st_size into a
  realloc - could crash the whole APIServer on a request for a
  nonexistent static asset)
- JString::setString(): always quote+escape the value instead of going
  through set()'s literal-value guess, which misclassified any string
  starting with digits (e.g. a UUID) as a bare numeric literal and wrote
  it unquoted, corrupting later edits to the same JSON document
- MString::remove() (both overloads): fixed an off-by-one that read one
  byte past the buffer on a completely full string (found via ASan under
  concurrent load)
- CGIFormData: added fields() so callers can iterate every parsed field
  without knowing names in advance (used to merge POST body into
  jet::Global::variables the same way query-string params already are)
2026-09-03 05:14:24 +00:00
Brad Arant ba85c5f2e5 Still parsing work. 2026-01-05 16:49:41 -08:00
Brad Arant d79697775b Continued work on parsing... 2025-12-31 16:56:00 -08:00
Brad Arant b5652e26cc Still working out parsing buffer stuff. 2025-12-29 16:09:57 -08:00
Brad Arant d415e0abd3 Still working out parsing buffer stuff. 2025-12-18 15:40:37 -08:00
Brad Arant ccfab5aecf Still working out parsing buffer stuff. 2025-12-17 17:07:14 -08:00
Brad Arant 0243468d44 Continued work on Parser. 2025-12-16 16:51:44 -08:00
Brad Arant d54aec1f06 Beginning parser work. 2025-12-15 16:53:49 -08:00
Brad Arant 1542fbe218 Still working out cgi variable stuff. 2025-12-10 16:47:53 -08:00
Brad Arant ab748802ee JFile seems to work well now. 2025-12-09 08:46:33 -08:00
Brad Arant ffa3361fd2 CGIFormData work in progress. 2025-12-08 16:35:15 -08:00
Brad Arant 4988f98223 Started work on JFile. 2025-12-04 17:04:55 -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 72c1286053 MFile stuff. 2025-06-20 00:42:24 +00:00
brad Arant a87ce0bab7 JSON file changes 2025-05-17 20:47:09 -07:00
Brad Arant 9cd8381845 significant work on cookies and cgi formdata variables. 2025-03-18 16:46:20 -07:00
Brad Arant bd5223ca36 more cgi processing multiform work. 2025-03-17 16:45:34 -07:00
brad Arant b774e50b59 more session work. 2025-03-17 07:45:02 -07:00
Brad Arant a3d5a4f93f more smartbuffer work. 2025-03-12 09:30:56 -07:00
Brad Arant 2866056072 more IMF work. 2025-03-11 16:59:16 -07:00
brad Arant fd7a9ed860 some smart buffer work. 2025-03-11 07:34:17 -07:00
brad Arant f35fa12902 Merge branch 'develop' of ssh://barant.com/git/CoreUtils into develop 2025-03-07 12:40:56 -08:00
Brad Arant 96f5c02435 Merge branch 'develop' of ssh://barant.com/git/CoreUtils into develop 2025-03-06 14:53:56 -08:00
Brad Arant 25916051e6 added CGIFormattedData object. 2025-03-06 14:47:57 -08:00
brad Arant 11f396a749 worked on IMF smartbuffers. 2025-02-21 13:22:57 -08:00
brad Arant 3f0a541e80 added byte count limiter for read on MString. 2025-02-14 11:56:11 -08:00
Brad Arant 5e6d162a05 added b64 encode/decode to MString. 2025-02-06 14:34:11 -08:00
Brad Arant d1c450fe48 added logic for toupper and tolower on MString. 2025-02-04 15:43:17 -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 f8557aa5f5 migrating conversion modifiers from JetCore::Global to MString. 2024-12-19 10:32:23 -08:00
barant 10df4a6a99 added changed event handler. 2024-12-18 11:26:58 -08:00
barant 7eb2417456 added a pretty output to JString. 2024-12-18 09:49:34 -08:00
barant d74fa9689d added a pretty output to JString. Initial. 2024-12-17 16:56:05 -08:00
barant d1e5e41ab2 JString fix to compress initial assignment JSON. 2024-12-17 09:58:56 -08:00
barant 95254310f0 JString fix to compress initial assignment JSON. 2024-12-17 09:56:55 -08:00
barant 83e9b8ca99 bug fixes on mstring and jstring. 2024-12-12 15:47:09 -08:00
barant 0d60cce8dc more serious work on JString. 2024-12-12 12:22:46 -08:00
barant c6e0486c14 Serious work on JString and some minor MString ajustments. 2024-12-11 16:58:34 -08:00
barant 7531c885a7 JString now streams properly. 2024-12-11 09:55:40 -08:00
barant 0baa44d076 messing around with jstring. 2024-12-10 17:10:49 -08:00
brad Arant c644d8346f fixed asInteger math issue. 2024-11-27 15:26:21 -08:00
brad Arant 6cd2fd6cc1 updated zstring_test to accomodate asInteger. 2024-11-27 15:18:32 -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 faa794cf6b Format the precision and eliminate trailing zeros for 12 digits. 2024-11-04 09:39:13 -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 8648ab3152 Added operator= integer operator. 2024-10-14 10:09:14 -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 6409bd2444 ignore string_tests. 2024-07-23 14:30:42 +00:00
Brad Arant 2adb523306 testing update. 2024-07-23 14:28:00 +00:00
Brad Arant dcf01ce555 initial compare coding. 2024-07-22 14:48:37 -07:00
Brad Arant 14a3991209 Merge branch 'develop' of ssh://barant.com/git/CoreUtils into develop 2024-07-22 06:58:17 -07:00
brad Arant b41e95250d Fixed write to not use reference. 2024-07-18 18:22:14 -07:00
Brad Arant 4945bbfc91 Updated write from ZString to not pass by reference. 2024-07-11 14:02:28 -07:00
Brad Arant d5bdfe8ca3 Added lineIsWhitespace function. 2024-07-11 13:53:53 -07:00
Brad Arant 81829f15f5 Added a zstring test. 2024-07-11 10:45:20 -07:00
Brad Arant 0ffc410a6a Fixed up File object to support better parameter options. 2024-07-09 14:29:15 -07:00
Brad Arant 7341d26852 Created read method on MString to read from sockets. 2024-07-09 12:56:10 -07:00
Brad Arant cca957b948 Removed stringstream from assignment from double. 2024-07-09 08:29:43 -07:00
Brad Arant bfe5283492 Change c++17 to c++20. Fixed formatting on assignment from double. 2024-07-09 08:21:11 -07:00
brad Arant 1c7f961255 Ignore xstring_test binaries. 2024-07-08 18:31:57 -07:00
brad Arant 363a6aa496 Fixed assignment of double to MString. 2024-07-08 18:27:05 -07:00
Brad Arant 5850c247dc Updated test scripts. 2024-07-08 14:13:57 -07:00
Brad Arant ce71aefaac Make some methods public for ZString. 2024-02-16 11:28:44 -08:00
Brad Arant 423af4eb52 Merge branch 'master' of ssh://barant.com/git/CoreUtils 2023-10-07 14:36:55 -07:00
Brad Arant c4b3955320 Added build and .history to .gitignore. 2023-10-07 14:35:10 -07:00
Brad Arant 8a9c1c3bd7 Worked on ZString, MString and JString 2023-10-05 17:57:01 -07:00
Brad Arant 88d51cb598 Added support for MString in File 2022-11-19 10:18:09 -08:00