From 3644ad9d70b52f877ce6a89ed61b23a4116f26ed Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 7 Mar 2018 15:00:11 +1100 Subject: [PATCH] Ignore CUI connections with more than 3 failed attempts. --- .../java/com/sk89q/worldedit/LocalSession.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/sk89q/worldedit/LocalSession.java b/core/src/main/java/com/sk89q/worldedit/LocalSession.java index fdeb0997..4e04d5b9 100644 --- a/core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -96,6 +96,7 @@ public class LocalSession { // Non-session related fields private transient LocalConfiguration config; private transient final AtomicBoolean dirty = new AtomicBoolean(); + private transient int failedCuiAttempts = 0; // Session related private transient RegionSelector selector = new CuboidRegionSelector(); @@ -1202,14 +1203,25 @@ public class LocalSession { */ public void handleCUIInitializationMessage(String text) { checkNotNull(text); + if (this.failedCuiAttempts > 3) { + return; + } - String[] split = text.split("\\|"); + String[] split = text.split("\\|", 2); if (split.length > 1 && split[0].equalsIgnoreCase("v")) { // enough fields and right message + if (split[1].length() > 4) { + this.failedCuiAttempts++; + return; + } setCUISupport(true); try { setCUIVersion(Integer.parseInt(split[1])); } catch (NumberFormatException e) { - WorldEdit.logger.warning("Error while reading CUI init message: " + e.getMessage()); + String msg = e.getMessage(); + if (msg != null && msg.length() > 256) msg = msg.substring(0, 256); + this.failedCuiAttempts++; + WorldEdit.logger.warning("Error while reading CUI init message: " + msg); + } } }