]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Fixed a possible buffer underrun when reading the MOTD file. Thanks to
authorAlexander Barton <alex@barton.de>
Mon, 24 Jan 2005 14:17:21 +0000 (14:17 +0000)
committerAlexander Barton <alex@barton.de>
Mon, 24 Jan 2005 14:17:21 +0000 (14:17 +0000)
Florian Westphal, <westphal@foo.fh-furtwangen.de>.

ChangeLog
src/ngircd/irc-info.c

index c09a8445ad1622524de2810216d7fea2dbc824ce..07eb17ca9fcd56a9f23655354b267010a5d9ecef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,8 @@
 
 ngIRCd CVSHEAD
 
+  - Fixed a possible buffer underrun when reading the MOTD file. Thanks
+    to Florian Westphal, <westphal@foo.fh-furtwangen.de>.
   - Code cleanups from Florian Westphal, <westphal@foo.fh-furtwangen.de>.
   - Fixed detection of IRC lines which are too long to send. Detected by
     Florian Westphal, <westphal@foo.fh-furtwangen.de>.
@@ -564,4 +566,4 @@ ngIRCd 0.0.1, 31.12.2001
 
 
 -- 
-$Id: ChangeLog,v 1.253 2005/01/20 00:11:49 alex Exp $
+$Id: ChangeLog,v 1.254 2005/01/24 14:17:21 alex Exp $
index 26306949ed865ecc014d0299770c73e5ee4ab790..f95d5c5dc972deaec4ebdda66bd79cc753c9642e 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-info.c,v 1.22 2004/05/07 11:19:21 alex Exp $";
+static char UNUSED id[] = "$Id: irc-info.c,v 1.23 2005/01/24 14:17:21 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -770,6 +770,7 @@ IRC_Show_MOTD( CLIENT *Client )
        BOOLEAN ok;
        CHAR line[127];
        FILE *fd;
+       UINT line_len;
 
        assert( Client != NULL );
 
@@ -790,8 +791,12 @@ IRC_Show_MOTD( CLIENT *Client )
        if( ! IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return DISCONNECTED;
        while( TRUE )
        {
-               if( ! fgets( line, 126, fd )) break;
-               if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
+               if( ! fgets( line, sizeof( line ), fd )) break;
+
+               line_len = strlen( line );
+               if( line_len > 0 ) pos--;
+               if( line[line_len] == '\n' ) line[line_len] = '\0';
+
                if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
                {
                        fclose( fd );