From 493ccd57f41bea8c9bca5311ca597b37fadc9e7f Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Sat, 29 Jan 2011 16:05:55 +0100 Subject: [PATCH] Clean up Validate_Prefix(); don't send punctuation in ERROR commands --- src/ngircd/conn.c | 4 ++-- src/ngircd/parse.c | 29 ++++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index af79c13f..032a6e91 100644 --- a/src/ngircd/conn.c +++ b/src/ngircd/conn.c @@ -980,7 +980,7 @@ Conn_Close( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClie if (FwdMsg) Conn_WriteStr(Idx, "ERROR :%s", FwdMsg); else - Conn_WriteStr(Idx, "ERROR :Closing connection."); + Conn_WriteStr(Idx, "ERROR :Closing connection"); } /* Try to write out the write buffer. Note: Handle_Write() eventually @@ -1276,7 +1276,7 @@ New_Connection(int Sock) "Refused connection from %s: too may connections (%ld) from this IP address!", ip_str, cnt); Simple_Message(new_sock, - "ERROR :Connection refused, too many connections from your IP address!"); + "ERROR :Connection refused, too many connections from your IP address"); close(new_sock); return -1; } diff --git a/src/ngircd/parse.c b/src/ngircd/parse.c index 479b3004..7c56a03d 100644 --- a/src/ngircd/parse.c +++ b/src/ngircd/parse.c @@ -178,7 +178,7 @@ Parse_Request( CONN_ID Idx, char *Request ) if( ! ptr ) { LogDebug("Connection %d: Parse error: prefix without command!?", Idx); - return Conn_WriteStr( Idx, "ERROR :Prefix without command!?" ); + return Conn_WriteStr(Idx, "ERROR :Prefix without command"); } *ptr = '\0'; #ifndef STRICT_RFC @@ -278,8 +278,9 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed ) assert( client != NULL ); /* only validate if this connection is already registered */ - if(( Client_Type( client ) != CLIENT_USER ) && ( Client_Type( client ) != CLIENT_SERVER ) && ( Client_Type( client ) != CLIENT_SERVICE )) - { + if (Client_Type(client) != CLIENT_USER + && Client_Type(client) != CLIENT_SERVER + && Client_Type(client) != CLIENT_SERVICE) { /* not registered, ignore prefix */ Req->prefix = NULL; return true; @@ -287,19 +288,25 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed ) /* check if client in prefix is known */ c = Client_Search( Req->prefix ); - if( ! c ) - { - Log( LOG_ERR, "Invalid prefix \"%s\", client not known (connection %d, command %s)!?", Req->prefix, Idx, Req->command ); - if( ! Conn_WriteStr( Idx, "ERROR :Invalid prefix \"%s\", client not known!?", Req->prefix )) *Closed = true; + if (!c) { + Log(LOG_ERR, + "Invalid prefix \"%s\", client not known (connection %d, command \"%s\")!?", + Req->prefix, Idx, Req->command); + if (!Conn_WriteStr(Idx, + "ERROR :Invalid prefix \"%s\", client not known", + Req->prefix)) + *Closed = true; return false; } /* check if the client named in the prefix is expected * to come from that direction */ - if( Client_NextHop( c ) != client ) - { - Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d, command %s)!", Req->prefix, Client_Mask( Conn_GetClient( Idx )), Idx, Req->command ); - Conn_Close( Idx, NULL, "Spoofed prefix", true); + if (Client_NextHop(c) != client) { + Log(LOG_ERR, + "Spoofed prefix \"%s\" from \"%s\" (connection %d, command \"%s\")!", + Req->prefix, Client_Mask(Conn_GetClient(Idx)), Idx, + Req->command); + Conn_Close(Idx, NULL, "Spoofed prefix", true); *Closed = true; return false; }