Files
aevolution/tests/fuzz/dev_session_fuzz.cpp
T
dingoandClaude Opus 5.5 c588be237c Fix M9.4-M9.7 review findings in the dev session stack
- TLS: replace send() with a bounded queue/flush; an interrupted record is
  retried with identical arguments and later frames wait behind it, so no
  queued frame is lost or reordered; close() flushes first.
- Carriers: server-issued 'I','N' | 48-bit epoch | 64-bit ordinal ids
  replace the aliasing low-32-bit packing; client sequences are kept
  separately for replies; out-of-range epochs are refused, never truncated.
- Grants: a durable, fsynced, fail-closed consumed-grant ledger
  (--session-grant-ledger, /objects/dev-session-grants.v1 in dev) keeps
  single-use grants consumed across process and pod restarts.
- Liveness: protocol v1 (undeployed) gains Heartbeat and the timeout close
  reason; both sides heartbeat when idle and treat 5 s of silence as dead.
- Client sends are bounded and unresolved tracking starts at send time.
- ci-client configures with an explicit C compiler.

Each finding has a regression test; ADR-0083, the schema, operations doc
and VALIDATION record the corrections.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 05:44:44 -04:00

70 lines
2.3 KiB
C++

#include "evo/network/protocol.hpp"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <span>
#include <vector>
// Any input: decoding never crashes, and an accepted message re-encodes to the same
// bytes (no field is trusted or silently dropped). Also streams through FrameReader.
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) {
using namespace evo::network;
const std::span<const std::uint8_t> bytes{data, size};
FrameReader reader;
for (std::size_t at = 0; at < size;) {
const auto taken = reader.feed(bytes.subspan(at, std::min<std::size_t>(7, size - at)));
if (!taken)
break;
at += *taken;
if (*taken == 0 && !reader.take())
std::abort();
(void)reader.take();
}
const auto frame = decode_frame(bytes);
if (!frame)
return 0;
std::vector<std::uint8_t> again;
switch (frame->type) {
case MessageType::hello:
if (const auto m = decode_hello(*frame))
again = *encode(*m);
break;
case MessageType::welcome:
if (const auto m = decode_welcome(*frame))
again = encode(*m);
break;
case MessageType::intent:
if (const auto m = decode_intent(*frame))
again = encode(*m);
break;
case MessageType::intent_result:
if (const auto m = decode_intent_result(*frame))
again = encode(*m);
break;
case MessageType::close:
if (const auto m = decode_close(*frame))
again = encode(*m);
break;
case MessageType::intent_outcome:
if (const auto m = decode_intent_outcome(*frame))
again = encode(*m);
break;
case MessageType::heartbeat:
if (decode_heartbeat(*frame))
again = encode_heartbeat();
break;
case MessageType::environment_view:
if (const auto m = decode_environment_view(*frame))
again = encode(m->first, m->second);
break;
case MessageType::organism_view:
if (const auto m = decode_organism_view(*frame))
again = encode(m->first, m->second);
break;
}
if (!again.empty() && !std::equal(again.begin(), again.end(), bytes.begin(), bytes.end()))
std::abort();
return 0;
}