]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
IRC: check full buffers
authorJānis Rūcis <parasti@gmail.com>
Wed, 31 Mar 2010 16:10:04 +0000 (19:10 +0300)
committernitroxis <nitroxis@wtwrp.de>
Fri, 10 Jan 2014 19:33:36 +0000 (20:33 +0100)
irc.c

diff --git a/irc.c b/irc.c
index 4e2e0944d9adb072ce1ab098ebd6cdbc78b807cd..a1ffb946b9e2c3a054f545b90ead0da2f90c2242 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -74,10 +74,16 @@ static void IRC_AddMessage(const char *message)
 {
        size_t len = strlen(message);
 
+       if (irc_outgoing.len + len + 2 > sizeof (irc_outgoing.data))
+       {
+               Con_Print("[IRC] Output buffer overflow.\n");
+               return;
+       }
+
        memcpy(irc_outgoing.data + irc_outgoing.len, message, sizeof (irc_outgoing.data) - irc_outgoing.len - 2);
-       memcpy(irc_outgoing.data + min(irc_outgoing.len + len, sizeof (irc_outgoing.data) - 2), "\r\n", 2);
+       memcpy(irc_outgoing.data + irc_outgoing.len + len, "\r\n", 2);
 
-       irc_outgoing.len = min(irc_outgoing.len + len + 2, sizeof (irc_outgoing.data));
+       irc_outgoing.len += len + 2;
 
        Con_Printf("[IRC] %lu bytes waiting to be written\n", (unsigned long) irc_outgoing.len);
 }
@@ -229,6 +235,14 @@ static void IRC_ProcessAllMessages(void)
 
                if (!nl)
                {
+                       if (remaining_len == irc_incoming.len && irc_incoming.len == sizeof (irc_incoming.data))
+                       {
+                               /* Full buffer, yet STILL no newline?  Flush it. */
+                               irc_incoming.len = 0;
+                               Con_Print("[IRC] Input buffer overflow.\n");
+                               return;
+                       }
+
                        /* Probably incomplete message. */
                        memmove(irc_incoming.data, remaining, remaining_len);
                        break;