Procházet zdrojové kódy

ircd/server: Avoid DoS when receiving empty lines from clients.

Luther Blissett před 3 roky
rodič
revize
5f1f79d4c5
1 změnil soubory, kde provedl 5 přidání a 5 odebrání
  1. 5 5
      bin/ircd/src/server.rs

+ 5 - 5
bin/ircd/src/server.rs

@@ -511,6 +511,11 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcServerConnection<C>
             return Err(Error::ChannelStopped)
             return Err(Error::ChannelStopped)
         }
         }
 
 
+        if line == "\n" || line == "\r\n" {
+            warn!("Closing connection.");
+            return Err(Error::ChannelStopped)
+        }
+
         if &line[(line.len() - 2)..] == "\r\n" {
         if &line[(line.len() - 2)..] == "\r\n" {
             // Remove CRLF
             // Remove CRLF
             line.pop();
             line.pop();
@@ -522,11 +527,6 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcServerConnection<C>
             return Err(Error::ChannelStopped)
             return Err(Error::ChannelStopped)
         }
         }
 
 
-        if line == "\n" {
-            warn!("Closing connection.");
-            return Err(Error::ChannelStopped)
-        }
-
         Ok(line.clone())
         Ok(line.clone())
     }
     }
 }
 }