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: lix-project/lix#325

Change-Id: Ieea1b0b8ac0f903d1e24e5b3e63cfe12eeec119d
This commit is contained in:
jade 2024-05-24 20:45:05 -06:00
parent 985ce8a865
commit c22a7f50cb
6 changed files with 25 additions and 39 deletions

View file

@ -264,14 +264,8 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
TrustedFlag trusted, RecursiveFlag recursive, WorkerProto::Version clientVersion, TrustedFlag trusted, RecursiveFlag recursive, WorkerProto::Version clientVersion,
Source & from, BufferedSink & to, WorkerProto::Op op) Source & from, BufferedSink & to, WorkerProto::Op op)
{ {
WorkerProto::ReadConn rconn { WorkerProto::ReadConn rconn{from, clientVersion};
.from = from, WorkerProto::WriteConn wconn{to, clientVersion};
.version = clientVersion,
};
WorkerProto::WriteConn wconn {
.to = to,
.version = clientVersion,
};
switch (op) { switch (op) {
@ -1030,10 +1024,7 @@ void processConnection(
auto temp = trusted auto temp = trusted
? store->isTrustedClient() ? store->isTrustedClient()
: std::optional { NotTrusted }; : std::optional { NotTrusted };
WorkerProto::WriteConn wconn { WorkerProto::WriteConn wconn {to, clientVersion};
.to = to,
.version = clientVersion,
};
WorkerProto::write(*store, wconn, temp); WorkerProto::write(*store, wconn, temp);
} }

View file

@ -68,10 +68,7 @@ struct RemoteStore::Connection
*/ */
operator WorkerProto::ReadConn () operator WorkerProto::ReadConn ()
{ {
return WorkerProto::ReadConn { return WorkerProto::ReadConn {from, daemonVersion};
.from = from,
.version = daemonVersion,
};
} }
/** /**
@ -84,10 +81,7 @@ struct RemoteStore::Connection
*/ */
operator WorkerProto::WriteConn () operator WorkerProto::WriteConn ()
{ {
return WorkerProto::WriteConn { return WorkerProto::WriteConn {to, daemonVersion};
.to = to,
.version = daemonVersion,
};
} }
virtual ~Connection(); virtual ~Connection();

View file

@ -466,7 +466,7 @@ void RemoteStore::addToStore(const ValidPathInfo & info, Source & source,
sink sink
<< exportMagic << exportMagic
<< printStorePath(info.path); << printStorePath(info.path);
WorkerProto::WriteConn nested { .to = sink, .version = conn->daemonVersion }; WorkerProto::WriteConn nested { sink, conn->daemonVersion };
WorkerProto::write(*this, nested, info.references); WorkerProto::write(*this, nested, info.references);
sink sink
<< (info.deriver ? printStorePath(*info.deriver) : "") << (info.deriver ? printStorePath(*info.deriver) : "")
@ -511,14 +511,13 @@ void RemoteStore::addMultipleToStore(
RepairFlag repair, RepairFlag repair,
CheckSigsFlag checkSigs) CheckSigsFlag checkSigs)
{ {
auto remoteVersion = getProtocol();
auto source = sinkToSource([&](Sink & sink) { auto source = sinkToSource([&](Sink & sink) {
sink << pathsToCopy.size(); sink << pathsToCopy.size();
for (auto & [pathInfo, pathSource] : pathsToCopy) { for (auto & [pathInfo, pathSource] : pathsToCopy) {
WorkerProto::Serialise<ValidPathInfo>::write(*this, WorkerProto::Serialise<ValidPathInfo>::write(*this,
WorkerProto::WriteConn { WorkerProto::WriteConn {sink, remoteVersion},
.to = sink,
.version = 16,
},
pathInfo); pathInfo);
pathSource->drainInto(sink); pathSource->drainInto(sink);
} }

View file

@ -368,15 +368,14 @@ void Store::addMultipleToStore(
RepairFlag repair, RepairFlag repair,
CheckSigsFlag checkSigs) CheckSigsFlag checkSigs)
{ {
auto remoteVersion = getProtocol();
auto expected = readNum<uint64_t>(source); auto expected = readNum<uint64_t>(source);
for (uint64_t i = 0; i < expected; ++i) { for (uint64_t i = 0; i < expected; ++i) {
// FIXME we should not be using the worker protocol here, let // FIXME we should not be using the worker protocol here at all!
// alone the worker protocol with a hard-coded version!
auto info = WorkerProto::Serialise<ValidPathInfo>::read(*this, auto info = WorkerProto::Serialise<ValidPathInfo>::read(*this,
WorkerProto::ReadConn { WorkerProto::ReadConn {source, remoteVersion}
.from = source, );
.version = 16,
});
info.ultimate = false; info.ultimate = false;
addToStore(info, source, repair, checkSigs); addToStore(info, source, repair, checkSigs);
} }

View file

@ -72,6 +72,10 @@ struct WorkerProto
struct ReadConn { struct ReadConn {
Source & from; Source & from;
Version version; 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 { struct WriteConn {
Sink & to; Sink & to;
Version version; Version version;
WriteConn(Sink & to, Version version) : to(to), version(version) {
assert(version >= MIN_SUPPORTED_WORKER_PROTO_VERSION);
}
}; };
/** /**

View file

@ -39,10 +39,8 @@ public:
StringSource from { expected }; StringSource from { expected };
Proto::template Serialise<T>::read( Proto::template Serialise<T>::read(
*LibStoreTest::store, *LibStoreTest::store,
typename Proto::ReadConn { typename Proto::ReadConn {from, version}
.from = from, );
.version = version,
});
}); });
ASSERT_EQ(got, value); ASSERT_EQ(got, value);
@ -60,10 +58,7 @@ public:
StringSink to; StringSink to;
Proto::write( Proto::write(
*LibStoreTest::store, *LibStoreTest::store,
typename Proto::WriteConn { typename Proto::WriteConn {to, version},
.to = to,
.version = version,
},
value); value);
if (testAccept()) if (testAccept())