Commit Graph
48 Commits
Author SHA1 Message Date
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 ArantandClaude Sonnet 5 6e4e463a96 Fix MString assignment operators leaving cursor at its old (stale) offset
operator=(MString)/operator=(ZString)/operator=(std::string)/operator=(const
char*)/operator=(char) all replaced the buffer's content via setSize()+
memcpy() but never reset cursor back to the start - setSize() preserves
the *offset* the cursor was already at (correct for its own use, growing
a buffer while keeping a read position stable), so a full content
replacement left the cursor sitting at whatever offset it had into the
*previous* content, not the new content. operator=(double)/operator=(int)
already did `cursor = data;` after the same setSize()+memcpy() pattern,
confirming this was the intended behavior everywhere - just missing from
the other five overloads.

This is invisible to JetCore's interpreter, which never reassigns an
already-read-from MString (each tag is a freshly parsed C++ object every
time its container is scanned, so a keyword's MString is never both read
and then reassigned on the same instance). It surfaced in a prototype JET
compiler (JetCore/jetc) built this session, which intentionally reuses
one persistent keyword slot across loop iterations instead of
reconstructing everything from text every pass - exactly the case this
bug needed. A <while expr="..."> loop reusing a slot for its condition
worked for two iterations (matching a decoy pattern: the second
assignment happened to land the stale cursor at the exact end of the
new, same-length content) and threw "operand is not valid" on the third,
since a keyword reassigned inside the loop body left the cursor already
at eod() from the read.

Verified via jstring_test/mstring_test/zstring_test/parser_test (no
regressions), JetCore's tests/posttest.sh and the two-process JSON
session persistence test (no regressions), and the jetc prototype's two
demo templates - both now produce byte-identical output to jet-2.0's
interpreter, including a <while> loop that mutates and rereads the same
keyword slot every iteration.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-23 19:18:17 -07:00
Brad ArantandClaude Sonnet 5 3e6e410fe8 Fix JFile empty-document seed and MString's ZString-source pointer/length mismatch
JFile.cpp: JFile and MFile both "virtual public MString" a single shared
base, so a virtual base is initialized only by the *most derived* class's
constructor. JFile's own constructor never mentions MString, so
JString's own "{}" default initializer never ran - a JFile backed by a
new or nonexistent file started as a raw empty string instead of a valid
empty JSON object. Every subsequent locate()/set() call then silently
misbehaved (no leading "{" for ifNext("{") to match, so writes landed at
offset 0 with no braces or separators - fields ended up prepended in
reverse order, concatenated with no delimiters at all). Fixed by seeding
"{}" via append (matching MFile's own load pattern) whenever the loaded
content is empty.

MString.cpp: several ZString-source copy paths (the ZString/MString copy
constructors, both assignment operators, operator<<(ZString), insert(),
write()) called zstring.getData() (the object's absolute start) paired
with zstring.getLength() (which is documented/implemented as "remaining
bytes from cursor to end", i.e. length - (cursor - data)). Pairing an
absolute start with a cursor-relative length silently corrupts any
cursor-advanced source: the copy starts from the wrong (too-early)
position but is truncated by exactly the amount the cursor had already
advanced, keeping unwanted leading bytes while dropping trailing ones.
Found via the CGIFormData-style resumability testing pattern used
elsewhere this session, triggered by JetCore's new "@name" session
variable feature stripping a sigil prefix via ifNext() before streaming
the remainder into an MString. Fixed by pairing zstring.getCursor()
(cursor-relative start) with zstring.getLength() consistently everywhere
this pattern appeared.

Verified via the existing jstring_test/mstring_test/zstring_test/
parser_test suites (all pass, no output changes) plus a new isolated
JFile round-trip test proving persistence across two separate process
instances sharing one file.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-23 18:44:59 -07:00
Brad ArantandClaude Sonnet 5 94d4a30e88 Fix CGI form/cookie data handling and CGI URL encode/decode
- CGIFormData: fix broken setSize()+read() double-length bug that
  corrupted every parsed body with a leading run of garbage bytes
  (setSize(contentLength) pre-set length before read()/write()
  appended on top of it); switch content-type checks from exact
  equality to startsWith() since a real multipart Content-Type
  always carries a boundary= parameter; implement the previously
  empty multipart/form-data branch (ordinary fields only, file
  uploads deferred to a separate upload mechanism per TODO.txt);
  restore operator[] real lookup logic (was hardcoded to echo the
  key back); default-initialize formdata to NULL; fix mismatched
  include guard (leftover from an IMFFormData.h copy-paste); drop
  the unused IMFHeader.h include that pulled in a broken,
  unrelated StreamReader.h dependency.
- CGIFormattedData: parameterize the split delimiter (was hardcoded
  to &, which silently broke cookie parsing since HTTP_COOKIE uses
  ; not &) and trim whitespace on each split token.
- MString::toCGI()/fromCGI(): were unimplemented stubs (always
  returned an empty string); implemented proper CGI percent-encode
  / percent-decode + space plus-encoding, and fixed the one caller
  that discarded fromCGIs return value instead of using it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-22 21:37:10 -07:00
Brad Arant 29c9a5b855 Fix MString::fromHex() silently swallowing the odd-length-input error
The Exception on the odd-length-input path was constructed but never
thrown (missing throw keyword) - the temporary was destroyed with no
effect, so execution fell through to an out-of-bounds nextChar() read
past the exhausted buffer instead of raising an error. Added the
missing throw.

Verified via full local compile: MString.cpp builds clean standalone;
a full-repo pass shows only the pre-existing, already-known
StreamReader.h-missing failures (7 files, unrelated to this change),
confirmed via each error log individually.
2026-08-22 19:52:35 -07:00
Brad Arant 829dc1a3c7 Fixed MString and MFile. 2025-12-04 16:40:11 -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 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
barant f8557aa5f5 migrating conversion modifiers from JetCore::Global to MString. 2024-12-19 10:32:23 -08:00
barant 7eb2417456 added a pretty output to JString. 2024-12-18 09:49:34 -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
Brad Arant faa794cf6b Format the precision and eliminate trailing zeros for 12 digits. 2024-11-04 09:39:13 -08:00
Brad Arant 8648ab3152 Added operator= integer operator. 2024-10-14 10:09: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 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 363a6aa496 Fixed assignment of double to MString. 2024-07-08 18:27:05 -07:00
Brad Arant beb3673241 Fixed == operator for empty string comparison. 2024-06-14 10:21:28 -07:00
Brad Arant f6e5e60e5b MString streaming work. 2024-03-26 11:09:07 -07:00
Brad Arant 37b9a5e316 Added ZString constructor for assignment on definition. 2024-02-16 14:38:04 -08:00
Brad Arant d020363bc9 Trying to fix MString assignments. 2023-10-10 15:49:46 -07:00
Brad Arant 7b333a3984 Added assignment to MString from ZString operator=. 2023-10-08 07:26:26 -07:00
Brad Arant 61d9f8015e Fixed pointer type on MString operator=. 2023-10-07 18:15:17 -07:00
Brad Arant b44a00862b Fixed leak in MString when assigning from another MString. 2023-10-07 18:04:23 -07:00
Matt Arant badfc4c709 merge 2023-10-07 02:31:33 +00:00
Matt Arant ac142b6a66 Core Changes 2023-10-06 18:32:17 +00: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 8f8c14d7b2 Changes to MString to add insert and remove methods. 2023-01-05 11:51:20 -08:00
Brad Arant 88d51cb598 Added support for MString in File 2022-11-19 10:18:09 -08:00
Brad Arant 2a349c6ceb Many fixes for MString, ZString. 2022-08-23 09:30:56 -07:00
Brad Arant d38b7f0c55 MString fixes. 2022-08-03 16:16:29 -07:00
Brad Arant 963a0561e8 Continues ZString and MString adjustments. 2022-07-30 18:04:27 -07:00
Brad Arant f8bc2df133 Merge up with master branch. 2022-07-28 18:52:30 -07:00
Brad Arant db801727c6 MString now string builds with << operator. 2022-07-28 18:36:44 -07:00
Brad Arant 036978130d MString updates. 2022-07-28 08:06:33 -07:00
Brad Arant d8df083d6b Added char * << to MString for string assignment. 2022-07-21 19:39:47 -07:00
Brad Arant 287933f9ce Added ZString.c_str() function; Added MStrin operator=. 2022-07-16 21:33:55 -07:00
Brad Arant e411d31cb6 MString edebugged. 2022-05-20 19:04:48 -07:00
Brad Arant b25650c5a7 << operator now outputs fulll ZString. 2022-04-04 13:35:15 -07:00
Brad Arant 59228ad356 Developed MString. 2022-03-15 20:07:43 -07:00