From 6d60a7f2855127b5c359e0d2326886d211cd93e8 Mon Sep 17 00:00:00 2001 From: dingo Date: Sun, 11 Oct 2026 13:08:33 -0400 Subject: [PATCH] Guard PostgreSQL row parser optionals --- docs/engineering/VALIDATION.md | 8 +++++++ src/persistence/region_lease_store.cpp | 29 +++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 2d4bc88..d424bcf 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -6927,3 +6927,11 @@ optional in the PostgreSQL reservation-row decoder at empty-string default to the hex parser; absent or malformed input still fails the existing validation path. The PostgreSQL job failed on this diagnostic, so the dependent server-image and Harbor jobs did not start. + +CI run #292 confirmed the reservation-input decoder repair, then clang analysis +reported additional optional-value and ineffective-move warnings in +`src/persistence/region_lease_store.cpp` while building the PostgreSQL target. +The affected action-record, migration-record, commit-status, publication-action, +and life-owner parsers now use safe optional defaults or checked copies; missing +mutation input retains its prior absent-value behavior. The PostgreSQL job failed +on these analyzer diagnostics, so the dependent image jobs did not start. diff --git a/src/persistence/region_lease_store.cpp b/src/persistence/region_lease_store.cpp index 65b2936..10ce06a 100644 --- a/src/persistence/region_lease_store.cpp +++ b/src/persistence/region_lease_store.cpp @@ -135,7 +135,7 @@ std::optional parse_action_record(const PgRows::value_typ return std::nullopt; std::optional> input; if (row[at + 5]) { - input = unhex_bytes(*row[at + 5]); + input = unhex_bytes(row[at + 5].value_or(std::string{})); if (!input) return std::nullopt; } @@ -394,14 +394,14 @@ load_cellular_profile_migration(Postgres& db, RegionKey key, const LeaseGrant& l const auto& row = (*rows)[0]; const auto source_sequence = parse_integer(row[0]); const auto source_commit = parse_uuid(row[1]); - const auto source_manifest = row[2] ? unhex<32>(*row[2]) : std::nullopt; - const auto source_payload = row[3] ? unhex<32>(*row[3]) : std::nullopt; - const auto source_versions = row[4] ? unhex_bytes(*row[4]) : std::nullopt; + const auto source_manifest = unhex<32>(row[2].value_or(std::string{})); + const auto source_payload = unhex<32>(row[3].value_or(std::string{})); + const auto source_versions = unhex_bytes(row[4].value_or(std::string{})); const auto target_sequence = parse_integer(row[5]); const auto target_commit = parse_uuid(row[6]); - const auto target_manifest = row[7] ? unhex<32>(*row[7]) : std::nullopt; - const auto target_payload = row[8] ? unhex<32>(*row[8]) : std::nullopt; - const auto target_versions = row[9] ? unhex_bytes(*row[9]) : std::nullopt; + const auto target_manifest = unhex<32>(row[7].value_or(std::string{})); + const auto target_payload = unhex<32>(row[8].value_or(std::string{})); + const auto target_versions = unhex_bytes(row[9].value_or(std::string{})); if (!source_sequence || !source_commit || !source_manifest || !source_payload || !source_versions || source_versions->size() != 36 || !target_sequence || !target_commit || !target_manifest || !target_payload || !target_versions || target_versions->size() != 36 || @@ -410,8 +410,8 @@ load_cellular_profile_migration(Postgres& db, RegionKey key, const LeaseGrant& l return std::unexpected{malformed(false)}; return std::optional{CellularProfileMigrationRecord{ *source_sequence, *source_commit, *source_manifest, *source_payload, - std::move(*source_versions), *target_sequence, *target_commit, *target_manifest, - *target_payload, std::move(*target_versions)}}; + source_versions.value_or(std::vector{}), *target_sequence, *target_commit, + *target_manifest, *target_payload, target_versions.value_or(std::vector{})}}; } std::expected @@ -464,7 +464,7 @@ std::expected resolve_cellular_region_commit( return std::unexpected{classify(rows.error())}; if (rows->size() != 1 || (*rows)[0].size() != 6 || !(*rows)[0][0]) return std::unexpected{malformed(false)}; - const auto& status = *(*rows)[0][0]; + const auto status = (*rows)[0][0].value_or(std::string{}); if (status == "absent") return ResolvedCommit{Resolution::absent, {}}; if (status == "conflict") @@ -493,10 +493,11 @@ load_cellular_publication_actions(Postgres& db, RegionKey key, const LeaseGrant& return std::optional>{}; if (rows->size() != 1 || (*rows)[0].size() != 1 || !(*rows)[0][0]) return std::unexpected{malformed(false)}; - auto actions = unhex_bytes(*(*rows)[0][0]); + auto actions = unhex_bytes((*rows)[0][0].value_or(std::string{})); if (!actions) return std::unexpected{malformed(false)}; - return std::optional>{std::move(*actions)}; + return std::optional>{ + actions.value_or(std::vector{})}; } std::expected, LeaseStoreFailure> @@ -574,7 +575,7 @@ find_region_action_record(Postgres& db, RegionKey key, const LeaseGrant& lease, const auto record = parse_action_record((*rows)[0], 0); if (!record) return std::unexpected{malformed(false)}; - return std::optional{*record}; + return std::optional{record.value_or(CommittedActionRecord{})}; } std::expected>, LeaseStoreFailure> @@ -1015,7 +1016,7 @@ primitive_life_owner(Postgres& db, RegionKey key, const LeaseGrant& lease, const const auto owner = parse_integer((*rows)[0][0]); if (!owner || *owner == 0) return std::unexpected{LifeReservationFailure{LifeReservationError::store, {}}}; - return std::optional{*owner}; + return std::optional{owner.value_or(0)}; } // Schema v12 probe records and handoff (ADR-0096). Shares this file's parsing rules.