From 10efecaa9cc1c9692a50c79768dcb902eeb4cf6c Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Wed, 1 May 2013 20:52:50 +0000
Subject: [PATCH]  * IRC Server tunnel: Reject bad protocols immediately

---
 .../src/net/i2p/i2ptunnel/I2PTunnelIRCServer.java     | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCServer.java
index e384665f6f..36f998242f 100644
--- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCServer.java
+++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCServer.java
@@ -72,6 +72,11 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
          "\r\n")
          .getBytes();
 
+    private static final String[] BAD_PROTOCOLS = {
+        "GET ", "HEAD ", "POST ", "GNUTELLA CONNECT", "\023BitTorrent protocol"
+    };
+
+
     /**
      * @throws IllegalArgumentException if the I2PTunnel does not contain
      *                                  valid config to contact the router
@@ -193,6 +198,12 @@ public class I2PTunnelIRCServer extends I2PTunnelServer implements Runnable {
             String s = DataHelper.readLine(in);
             if (s == null)
                 throw new IOException("EOF reached before the end of the headers [" + buf.toString() + "]");
+            if (lineCount == 0) {
+                for (int i = 0; i < BAD_PROTOCOLS.length; i++) {
+                    if (s.startsWith(BAD_PROTOCOLS[i]))
+                        throw new IOException("Bad protocol " + BAD_PROTOCOLS[i]);
+                }
+            }
             if (++lineCount > 10)
                 throw new IOException("Too many lines before USER or SERVER, giving up");
             if (System.currentTimeMillis() > expire)
-- 
GitLab