Commit Graph
2 Commits
Author SHA1 Message Date
retoorandClaude Opus 4.8 bfc117b0c5 whatsapp: fix the real root cause of the pair-success crash (lifetime UB in serialize)
Replaying the captured failing frame proved the std::vector max_size() abort was
never a parser bug. It was an object-lifetime bug in WaDevice::serialize():

    put_blob(b, Bytes((jid ? *jid : "").begin(), (jid ? *jid : "").end()));

(jid ? *jid : "") builds a fresh temporary std::string for each evaluation, so
begin() and end() came from two different, already-destroyed objects; the range
constructor computed a garbage length and vector threw. It only misfired once
jid was set (after the phone scanned), which is why every parser test and the
initial unpaired save passed. Fixed by binding the value to a named const
std::string before taking iterators.

- src/whatsapp/wa_device.cpp: bind jid/lid before iterating; audited the tree
  for the same two-temporaries pattern (no other instances).
- tests/whatsapp_test.cpp: test_device round-trips a PAIRED device (jid+lid set,
  synthetic identifiers), the populated case that triggers the bug; runs under
  tools/san-whatsapp.sh.
- docs/whatsapp.md 13.7: records the real root cause and closes the open item.
- docs/cpp-safety.md: adds the object-lifetime rule (never take iterators from a
  temporary you rebuild) as a distinct bug class from size overflow.

Verified: replaying the captured pair-success frame now serializes, saves, and
encodes the response with no throw; build, whatsapp_test, make lint, and
tools/san-whatsapp.sh all green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-27 19:25:50 +01:00
retoorandClaude Opus 4.8 d34db8f215 cpp-safety: add the playbook doc and AGENTS rule (missed by *.md ignore)
docs/cpp-safety.md (the four-layer safe-C++ playbook and design decisions) and
the AGENTS.md standing rule were skipped by taicpp/.gitignore's *.md pattern in
79ae6f2; force-add them so the policy is actually in the tree, matching how the
other docs are tracked.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-27 19:04:11 +01:00