From 371af24423da2b73e46002f8b97bb1a6ffa5c097 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Tue, 3 Mar 2026 11:24:39 +0000 Subject: [PATCH 1/5] Remove protocol downgrade restriction --- src/lib/client/Client.cpp | 37 ++++--------------------------------- src/lib/client/Client.h | 1 - 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 88568ff96..570d38d91 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -651,26 +651,6 @@ void Client::handleClipboardGrabbed(const Event &event, void *) } } -bool Client::isCompatible(int major, int minor) const -{ - const std::map> compatibleTable{ - {6, {7, 8}}, // 1.6 is compatible with 1.7 and 1.8 - {7, {8}} // 1.7 is compatible with 1.8 - }; - - bool isCompatible = false; - - if (major == kProtocolMajorVersion) { - auto versions = compatibleTable.find(minor); - if (versions != compatibleTable.end()) { - auto compatibleVersions = versions->second; - isCompatible = compatibleVersions.find(kProtocolMinorVersion) != compatibleVersions.end(); - } - } - - return isCompatible; -} - void Client::handleHello(const Event &, void *) { SInt16 major, minor; @@ -682,24 +662,15 @@ void Client::handleHello(const Event &, void *) } // check versions - LOG((CLOG_DEBUG1 "got hello version %d.%d", major, minor)); + LOG((CLOG_DEBUG "got hello version %d.%d", major, minor)); SInt16 helloBackMajor = kProtocolMajorVersion; SInt16 helloBackMinor = kProtocolMinorVersion; - if (isCompatible(major, minor)) { - // because 1.6 is comptable with 1.7 and 1.8 - downgrading protocol for - // server - LOG((CLOG_NOTE "downgrading protocol version for server")); - helloBackMinor = minor; - } else if (major < kProtocolMajorVersion || (major == kProtocolMajorVersion && minor < kProtocolMinorVersion)) { - sendConnectionFailedEvent(XIncompatibleClient(major, minor).what()); - cleanupTimer(); - cleanupConnection(); - return; - } + LOG((CLOG_NOTE "downgrading protocol version for server")); + helloBackMinor = minor; // say hello back - LOG((CLOG_DEBUG1 "say hello version %d.%d", helloBackMajor, helloBackMinor)); + LOG((CLOG_DEBUG "say hello version %d.%d", helloBackMajor, helloBackMinor)); ProtocolUtil::writef(m_stream, kMsgHelloBack, helloBackMajor, helloBackMinor, &m_name); // now connected but waiting to complete handshake diff --git a/src/lib/client/Client.h b/src/lib/client/Client.h index 7460b0bb1..e0f341ad5 100644 --- a/src/lib/client/Client.h +++ b/src/lib/client/Client.h @@ -217,7 +217,6 @@ class Client : public IClient, public INode void handleDisconnected(const Event &, void *); void handleShapeChanged(const Event &, void *); void handleClipboardGrabbed(const Event &, void *); - bool isCompatible(int major, int minor) const; void handleHello(const Event &, void *); void handleSuspend(const Event &event, void *); void handleResume(const Event &event, void *); From 4adb75766065f0ae2664e73d050d5c24b802f9eb Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Tue, 3 Mar 2026 11:33:27 +0000 Subject: [PATCH 2/5] Conditionally downgrade --- src/lib/client/Client.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 570d38d91..69af89b9f 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -666,8 +666,14 @@ void Client::handleHello(const Event &, void *) SInt16 helloBackMajor = kProtocolMajorVersion; SInt16 helloBackMinor = kProtocolMinorVersion; - LOG((CLOG_NOTE "downgrading protocol version for server")); - helloBackMinor = minor; + if (major < kProtocolMajorVersion || (major == kProtocolMajorVersion && minor < kProtocolMinorVersion)) { + helloBackMajor = major; + helloBackMinor = minor; + LOG_NOTE( + "downgrading protocol version for server from %d.%d to %d.%d", // + kProtocolMajorVersion, kProtocolMinorVersion, helloBackMajor, helloBackMinor + ); + } // say hello back LOG((CLOG_DEBUG "say hello version %d.%d", helloBackMajor, helloBackMinor)); From f86d529ace6bd018a1dcc6b76cec43ddd871d8b4 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Tue, 3 Mar 2026 11:39:19 +0000 Subject: [PATCH 3/5] Fix log message to clarify client protocol version downgrade --- src/lib/client/Client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 69af89b9f..2f81d9338 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -670,7 +670,7 @@ void Client::handleHello(const Event &, void *) helloBackMajor = major; helloBackMinor = minor; LOG_NOTE( - "downgrading protocol version for server from %d.%d to %d.%d", // + "downgrading client protocol version from %d.%d to %d.%d", // kProtocolMajorVersion, kProtocolMinorVersion, helloBackMajor, helloBackMinor ); } From 460c06e9223281d226308147feeff7ea7ec2bc16 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Tue, 3 Mar 2026 11:54:59 +0000 Subject: [PATCH 4/5] Restrict client protocol version downgrade to minor versions only --- src/lib/client/Client.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 2f81d9338..31fee69a0 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -666,13 +666,19 @@ void Client::handleHello(const Event &, void *) SInt16 helloBackMajor = kProtocolMajorVersion; SInt16 helloBackMinor = kProtocolMinorVersion; - if (major < kProtocolMajorVersion || (major == kProtocolMajorVersion && minor < kProtocolMinorVersion)) { + // only allow client minor version to downgrade, as major versions will likely not be compatible. + if (major == kProtocolMajorVersion && minor < kProtocolMinorVersion) { helloBackMajor = major; helloBackMinor = minor; LOG_NOTE( "downgrading client protocol version from %d.%d to %d.%d", // kProtocolMajorVersion, kProtocolMinorVersion, helloBackMajor, helloBackMinor ); + } else if (major != kProtocolMajorVersion) { + sendConnectionFailedEvent(XIncompatibleClient(major, minor).what()); + cleanupTimer(); + cleanupConnection(); + return; } // say hello back From 032595a2a7ee9f0f839e87b5561bd544fd83dd3e Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Tue, 3 Mar 2026 12:49:21 +0000 Subject: [PATCH 5/5] Remove redundant assignment of helloBackMajor in protocol downgrade handling --- src/lib/client/Client.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index 31fee69a0..d23077f6b 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -668,7 +668,6 @@ void Client::handleHello(const Event &, void *) // only allow client minor version to downgrade, as major versions will likely not be compatible. if (major == kProtocolMajorVersion && minor < kProtocolMinorVersion) { - helloBackMajor = major; helloBackMinor = minor; LOG_NOTE( "downgrading client protocol version from %d.%d to %d.%d", //