diff options
author | Jade Lovelace <lix@jade.fyi> | 2024-05-24 20:45:05 -0600 |
---|---|---|
committer | Jade Lovelace <lix@jade.fyi> | 2024-06-16 19:15:08 -0700 |
commit | c22a7f50cb4a476f0c276d8e0d2194da5144ce92 (patch) | |
tree | 2fe48d0c3c57c90394c9f834306c4cac67a10360 /src | |
parent | 985ce8a865e39857e5c582588ccf5eed90fd0fc8 (diff) |
libstore: refuse to serialise ancient protocols
We don't want to deal with these at all, let's stop doing so.
(marking this one as the fix commit since its immediate predecessors
aren't the complete fix)
Fixes: https://git.lix.systems/lix-project/lix/issues/325
Change-Id: Ieea1b0b8ac0f903d1e24e5b3e63cfe12eeec119d
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/daemon.cc | 15 | ||||
-rw-r--r-- | src/libstore/remote-store-connection.hh | 10 | ||||
-rw-r--r-- | src/libstore/remote-store.cc | 9 | ||||
-rw-r--r-- | src/libstore/store-api.cc | 11 | ||||
-rw-r--r-- | src/libstore/worker-protocol.hh | 8 |
5 files changed, 22 insertions, 31 deletions
diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index e256ad1de..c89b5f5b3 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -264,14 +264,8 @@ static void performOp(TunnelLogger * logger, ref<Store> store, TrustedFlag trusted, RecursiveFlag recursive, WorkerProto::Version clientVersion, Source & from, BufferedSink & to, WorkerProto::Op op) { - WorkerProto::ReadConn rconn { - .from = from, - .version = clientVersion, - }; - WorkerProto::WriteConn wconn { - .to = to, - .version = clientVersion, - }; + WorkerProto::ReadConn rconn{from, clientVersion}; + WorkerProto::WriteConn wconn{to, clientVersion}; switch (op) { @@ -1030,10 +1024,7 @@ void processConnection( auto temp = trusted ? store->isTrustedClient() : std::optional { NotTrusted }; - WorkerProto::WriteConn wconn { - .to = to, - .version = clientVersion, - }; + WorkerProto::WriteConn wconn {to, clientVersion}; WorkerProto::write(*store, wconn, temp); } diff --git a/src/libstore/remote-store-connection.hh b/src/libstore/remote-store-connection.hh index 082874cec..1647afd0d 100644 --- a/src/libstore/remote-store-connection.hh +++ b/src/libstore/remote-store-connection.hh @@ -68,10 +68,7 @@ struct RemoteStore::Connection */ operator WorkerProto::ReadConn () { - return WorkerProto::ReadConn { - .from = from, - .version = daemonVersion, - }; + return WorkerProto::ReadConn {from, daemonVersion}; } /** @@ -84,10 +81,7 @@ struct RemoteStore::Connection */ operator WorkerProto::WriteConn () { - return WorkerProto::WriteConn { - .to = to, - .version = daemonVersion, - }; + return WorkerProto::WriteConn {to, daemonVersion}; } virtual ~Connection(); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 82181b921..d445cbcb6 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -466,7 +466,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, sink << exportMagic << printStorePath(info.path); - WorkerProto::WriteConn nested { .to = sink, .version = conn->daemonVersion }; + WorkerProto::WriteConn nested { sink, conn->daemonVersion }; WorkerProto::write(*this, nested, info.references); sink << (info.deriver ? printStorePath(*info.deriver) : "") @@ -511,14 +511,13 @@ void RemoteStore::addMultipleToStore( RepairFlag repair, CheckSigsFlag checkSigs) { + auto remoteVersion = getProtocol(); + auto source = sinkToSource([&](Sink & sink) { sink << pathsToCopy.size(); for (auto & [pathInfo, pathSource] : pathsToCopy) { WorkerProto::Serialise<ValidPathInfo>::write(*this, - WorkerProto::WriteConn { - .to = sink, - .version = 16, - }, + WorkerProto::WriteConn {sink, remoteVersion}, pathInfo); pathSource->drainInto(sink); } diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index e0e842060..a10e5df0a 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -368,15 +368,14 @@ void Store::addMultipleToStore( RepairFlag repair, CheckSigsFlag checkSigs) { + auto remoteVersion = getProtocol(); + auto expected = readNum<uint64_t>(source); for (uint64_t i = 0; i < expected; ++i) { - // FIXME we should not be using the worker protocol here, let - // alone the worker protocol with a hard-coded version! + // FIXME we should not be using the worker protocol here at all! auto info = WorkerProto::Serialise<ValidPathInfo>::read(*this, - WorkerProto::ReadConn { - .from = source, - .version = 16, - }); + WorkerProto::ReadConn {source, remoteVersion} + ); info.ultimate = false; addToStore(info, source, repair, checkSigs); } diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh index cc083a551..5f24c189f 100644 --- a/src/libstore/worker-protocol.hh +++ b/src/libstore/worker-protocol.hh @@ -72,6 +72,10 @@ struct WorkerProto struct ReadConn { Source & from; Version version; + + ReadConn(Source & from, Version version) : from(from), version(version) { + assert(version >= MIN_SUPPORTED_WORKER_PROTO_VERSION); + } }; /** @@ -81,6 +85,10 @@ struct WorkerProto struct WriteConn { Sink & to; Version version; + + WriteConn(Sink & to, Version version) : to(to), version(version) { + assert(version >= MIN_SUPPORTED_WORKER_PROTO_VERSION); + } }; /** |