aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-24 15:57:49 +0100
committereldritch horrors <pennae@lix.systems>2024-03-24 18:45:22 +0000
commitc856b82c2e29bc900a6d4135b8bb5cc759630bac (patch)
treed2e9765809ddc638aa81dc7fb1bcedf912cc4666 /src/libstore
parent3e428f2289d0cb1277e013cd7f37754d7c533ddf (diff)
libstore: despecialcase protocol version check
protocol versions are sent as u64. on the peer we read them as uint64, check that the upper half is 0, and throw an exception if not. we then read an arbitrary amount of data from the peer and dump it to the user terminal. this is a little bit ridiculous, can never happen in correct implementation, and is severly untested. let us just drop it entirely. Change-Id: Ibd2f53a765341ed6439d40d9d1eac11e79c6b5e3
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/legacy-ssh-store.cc17
-rw-r--r--src/libstore/remote-store.cc17
2 files changed, 7 insertions, 27 deletions
diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc
index 890c8a149..2d8667a85 100644
--- a/src/libstore/legacy-ssh-store.cc
+++ b/src/libstore/legacy-ssh-store.cc
@@ -124,20 +124,9 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
conn->to << SERVE_MAGIC_1 << SERVE_PROTOCOL_VERSION;
conn->to.flush();
- StringSink saved;
- try {
- TeeSource tee(conn->from, saved);
- unsigned int magic = readInt(tee);
- if (magic != SERVE_MAGIC_2)
- throw Error("'nix-store --serve' protocol mismatch from '%s'", host);
- } catch (SerialisationError & e) {
- /* In case the other side is waiting for our input,
- close it. */
- conn->sshConn->in.close();
- auto msg = conn->from.drain();
- throw Error("'nix-store --serve' protocol mismatch from '%s', got '%s'",
- host, chomp(saved.s + msg));
- }
+ uint64_t magic = readLongLong(conn->from);
+ if (magic != SERVE_MAGIC_2)
+ throw Error("'nix-store --serve' protocol mismatch from '%s'", host);
conn->remoteVersion = readInt(conn->from);
if (GET_PROTOCOL_MAJOR(conn->remoteVersion) != 0x200)
throw Error("unsupported 'nix-store --serve' protocol version on '%s'", host);
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 7572473cf..f0dbe8e21 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -69,19 +69,10 @@ void RemoteStore::initConnection(Connection & conn)
conn.from.endOfFileError = "Nix daemon disconnected unexpectedly (maybe it crashed?)";
conn.to << WORKER_MAGIC_1;
conn.to.flush();
- StringSink saved;
- try {
- TeeSource tee(conn.from, saved);
- unsigned int magic = readInt(tee);
- if (magic != WORKER_MAGIC_2)
- throw Error("protocol mismatch");
- } catch (SerialisationError & e) {
- /* In case the other side is waiting for our input, close
- it. */
- conn.closeWrite();
- auto msg = conn.from.drain();
- throw Error("protocol mismatch, got '%s'", chomp(saved.s + msg));
- }
+
+ uint64_t magic = readLongLong(conn.from);
+ if (magic != WORKER_MAGIC_2)
+ throw Error("protocol mismatch");
conn.from >> conn.daemonVersion;
if (GET_PROTOCOL_MAJOR(conn.daemonVersion) != GET_PROTOCOL_MAJOR(PROTOCOL_VERSION))