From 4cc6854a6771befda9d5ac1e007e97b29b48e80b Mon Sep 17 00:00:00 2001 From: Benjamin James Harrison-Sims Date: Sun, 14 Apr 2013 03:09:29 +0100 Subject: [PATCH 1/2] Prevent handshake spam from invalid names. --- ...nt-handshake-spam-from-invalid-names.patch | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 CraftBukkit-Patches/0039-Prevent-handshake-spam-from-invalid-names.patch diff --git a/CraftBukkit-Patches/0039-Prevent-handshake-spam-from-invalid-names.patch b/CraftBukkit-Patches/0039-Prevent-handshake-spam-from-invalid-names.patch new file mode 100644 index 0000000000..ce73c13852 --- /dev/null +++ b/CraftBukkit-Patches/0039-Prevent-handshake-spam-from-invalid-names.patch @@ -0,0 +1,21 @@ +From f22c9b13df956663f41d000bea443a737624b91c Mon Sep 17 00:00:00 2001 +From: Benjamin James Harrison-Sims +Date: Sun, 14 Apr 2013 03:08:51 +0100 +Subject: [PATCH] Prevent handshake spam from invalid names. + + +diff --git a/src/main/java/net/minecraft/server/Packet2Handshake.java b/src/main/java/net/minecraft/server/Packet2Handshake.java +index 343af93..920e045 100644 +--- a/src/main/java/net/minecraft/server/Packet2Handshake.java ++++ b/src/main/java/net/minecraft/server/Packet2Handshake.java +@@ -19,6 +19,7 @@ public class Packet2Handshake extends Packet { + this.b = a(datainputstream, 16); + this.c = a(datainputstream, 255); + this.d = datainputstream.readInt(); ++ if(!this.b.matches("^[a-zA-Z0-9_]{3,16}$")){throw new IOException("Invalid name!");}// Spigot + } + + public void a(DataOutputStream dataoutputstream) throws IOException { // CraftBukkit - throws IOException +-- +1.8.2.1 + From 9a75a123f5f2205cbc636138eff8097348507548 Mon Sep 17 00:00:00 2001 From: Benjamin James Harrison-Sims Date: Sun, 14 Apr 2013 03:25:35 +0100 Subject: [PATCH 2/2] Use Pattern --- ...nt-handshake-spam-from-invalid-names.patch | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/CraftBukkit-Patches/0039-Prevent-handshake-spam-from-invalid-names.patch b/CraftBukkit-Patches/0039-Prevent-handshake-spam-from-invalid-names.patch index ce73c13852..fde4459178 100644 --- a/CraftBukkit-Patches/0039-Prevent-handshake-spam-from-invalid-names.patch +++ b/CraftBukkit-Patches/0039-Prevent-handshake-spam-from-invalid-names.patch @@ -1,21 +1,50 @@ -From f22c9b13df956663f41d000bea443a737624b91c Mon Sep 17 00:00:00 2001 +From d8a60325ae53f811ad456e3b0738de3ccd02360e Mon Sep 17 00:00:00 2001 From: Benjamin James Harrison-Sims Date: Sun, 14 Apr 2013 03:08:51 +0100 Subject: [PATCH] Prevent handshake spam from invalid names. diff --git a/src/main/java/net/minecraft/server/Packet2Handshake.java b/src/main/java/net/minecraft/server/Packet2Handshake.java -index 343af93..920e045 100644 +index 343af93..aa6609b 100644 --- a/src/main/java/net/minecraft/server/Packet2Handshake.java +++ b/src/main/java/net/minecraft/server/Packet2Handshake.java -@@ -19,6 +19,7 @@ public class Packet2Handshake extends Packet { +@@ -1,5 +1,7 @@ + package net.minecraft.server; + ++import org.bukkit.craftbukkit.Spigot; ++ + import java.io.DataInputStream; + import java.io.DataOutputStream; + +@@ -19,6 +21,7 @@ public class Packet2Handshake extends Packet { this.b = a(datainputstream, 16); this.c = a(datainputstream, 255); this.d = datainputstream.readInt(); -+ if(!this.b.matches("^[a-zA-Z0-9_]{3,16}$")){throw new IOException("Invalid name!");}// Spigot ++ if(!Spigot.validName.matcher(this.b).matches()) throw new IOException("Invalid name!"); // Spigot } public void a(DataOutputStream dataoutputstream) throws IOException { // CraftBukkit - throws IOException +diff --git a/src/main/java/org/bukkit/craftbukkit/Spigot.java b/src/main/java/org/bukkit/craftbukkit/Spigot.java +index 504bd8b..5bf5c10 100644 +--- a/src/main/java/org/bukkit/craftbukkit/Spigot.java ++++ b/src/main/java/org/bukkit/craftbukkit/Spigot.java +@@ -9,6 +9,8 @@ import org.bukkit.configuration.file.YamlConfiguration; + + import java.util.List; + import java.util.logging.Level; ++import java.util.regex.Pattern; ++ + import net.minecraft.server.EntityPlayer; + import org.bukkit.Bukkit; + import org.spigotmc.Metrics; +@@ -25,6 +27,7 @@ public class Spigot { + private static Metrics metrics; + public static List bungeeIPs; + public static int textureResolution = 16; ++ public static final Pattern validName = Pattern.compile("^[a-zA-Z0-9_]{3,16}$"); + + public static void initialize(CraftServer server, SimpleCommandMap commandMap, YamlConfiguration configuration) { + commandMap.register("bukkit", new org.bukkit.craftbukkit.command.TicksPerSecondCommand("tps")); -- 1.8.2.1