Skip to content

Commit db1b7ef

Browse files
authored
Remove protocol downgrade restriction (#161)
* Remove protocol downgrade restriction * Conditionally downgrade * Fix log message to clarify client protocol version downgrade * Restrict client protocol version downgrade to minor versions only * Remove redundant assignment of helloBackMajor in protocol downgrade handling
1 parent dcf37d1 commit db1b7ef

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

src/lib/client/Client.cpp

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -651,26 +651,6 @@ void Client::handleClipboardGrabbed(const Event &event, void *)
651651
}
652652
}
653653

654-
bool Client::isCompatible(int major, int minor) const
655-
{
656-
const std::map<int, std::set<int>> compatibleTable{
657-
{6, {7, 8}}, // 1.6 is compatible with 1.7 and 1.8
658-
{7, {8}} // 1.7 is compatible with 1.8
659-
};
660-
661-
bool isCompatible = false;
662-
663-
if (major == kProtocolMajorVersion) {
664-
auto versions = compatibleTable.find(minor);
665-
if (versions != compatibleTable.end()) {
666-
auto compatibleVersions = versions->second;
667-
isCompatible = compatibleVersions.find(kProtocolMinorVersion) != compatibleVersions.end();
668-
}
669-
}
670-
671-
return isCompatible;
672-
}
673-
674654
void Client::handleHello(const Event &, void *)
675655
{
676656
SInt16 major, minor;
@@ -682,24 +662,26 @@ void Client::handleHello(const Event &, void *)
682662
}
683663

684664
// check versions
685-
LOG((CLOG_DEBUG1 "got hello version %d.%d", major, minor));
665+
LOG((CLOG_DEBUG "got hello version %d.%d", major, minor));
686666
SInt16 helloBackMajor = kProtocolMajorVersion;
687667
SInt16 helloBackMinor = kProtocolMinorVersion;
688668

689-
if (isCompatible(major, minor)) {
690-
// because 1.6 is comptable with 1.7 and 1.8 - downgrading protocol for
691-
// server
692-
LOG((CLOG_NOTE "downgrading protocol version for server"));
669+
// only allow client minor version to downgrade, as major versions will likely not be compatible.
670+
if (major == kProtocolMajorVersion && minor < kProtocolMinorVersion) {
693671
helloBackMinor = minor;
694-
} else if (major < kProtocolMajorVersion || (major == kProtocolMajorVersion && minor < kProtocolMinorVersion)) {
672+
LOG_NOTE(
673+
"downgrading client protocol version from %d.%d to %d.%d", //
674+
kProtocolMajorVersion, kProtocolMinorVersion, helloBackMajor, helloBackMinor
675+
);
676+
} else if (major != kProtocolMajorVersion) {
695677
sendConnectionFailedEvent(XIncompatibleClient(major, minor).what());
696678
cleanupTimer();
697679
cleanupConnection();
698680
return;
699681
}
700682

701683
// say hello back
702-
LOG((CLOG_DEBUG1 "say hello version %d.%d", helloBackMajor, helloBackMinor));
684+
LOG((CLOG_DEBUG "say hello version %d.%d", helloBackMajor, helloBackMinor));
703685
ProtocolUtil::writef(m_stream, kMsgHelloBack, helloBackMajor, helloBackMinor, &m_name);
704686

705687
// now connected but waiting to complete handshake

src/lib/client/Client.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ class Client : public IClient, public INode
217217
void handleDisconnected(const Event &, void *);
218218
void handleShapeChanged(const Event &, void *);
219219
void handleClipboardGrabbed(const Event &, void *);
220-
bool isCompatible(int major, int minor) const;
221220
void handleHello(const Event &, void *);
222221
void handleSuspend(const Event &event, void *);
223222
void handleResume(const Event &event, void *);

0 commit comments

Comments
 (0)