浏览代码

* Added a limit of 1MB of pending data in the write fifo for non-server sockets. Connections that go over the limit are closed.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@13469 54d463be-8e91-2dee-dedb-b68131a5f0ec
FlavioJS 16 年之前
父节点
当前提交
672dbf2946
共有 2 个文件被更改,包括 13 次插入1 次删除
  1. 2 0
      Changelog-Trunk.txt
  2. 11 1
      src/common/socket.c

+ 2 - 0
Changelog-Trunk.txt

@@ -4,6 +4,8 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2009/01/21
+	* Added a limit of 1MB of pending data in the write fifo for non-server sockets.
+	  Connections that go over the limit are closed.
 	* Replaced the fake timer heap (sorted array) with a real heap. (improves performance) [FlavioJS]
 2009/01/20
 	* Added a generic binary heap implementation based on defines. [FlavioJS]

+ 11 - 1
src/common/socket.c

@@ -205,6 +205,10 @@ int naddr_ = 0;   // # of ip addresses
 // initial send buffer size (will be resized as needed)
 #define WFIFO_SIZE (16*1024)
 
+// Maximum size of pending data in the write fifo. (for non-server connections)
+// The connection is closed if it goes over the limit.
+#define WFIFO_MAX (1*1024*1024)
+
 struct socket_data* session[FD_SETSIZE];
 
 #ifdef SEND_SHORTLIST
@@ -625,12 +629,18 @@ int WFIFOSET(int fd, size_t len)
 	if(s->wdata_size+len > s->max_wdata)
 	{	// actually there was a buffer overflow already
 		uint32 ip = s->client_addr;
-		ShowFatalError("WFIFOSET: Write Buffer Overflow. Connection %d (%d.%d.%d.%d) has written %d bytes on a %d/%d bytes buffer.\n", fd, CONVIP(ip), len, s->wdata_size, s->max_wdata);
+		ShowFatalError("WFIFOSET: Write Buffer Overflow. Connection %d (%d.%d.%d.%d) has written %u bytes on a %u/%u bytes buffer.\n", fd, CONVIP(ip), (unsigned int)len, (unsigned int)s->wdata_size, (unsigned int)s->max_wdata);
 		ShowDebug("Likely command that caused it: 0x%x\n", (*(unsigned short*)(s->wdata + s->wdata_size)));
 		// no other chance, make a better fifo model
 		exit(EXIT_FAILURE);
 	}
 
+	if( !s->flag.server && s->wdata_size+len > WFIFO_MAX )
+	{// reached maximum write fifo size
+		set_eof(fd);
+		return 0;
+	}
+
 	s->wdata_size += len;
 	//If the interserver has 200% of its normal size full, flush the data.
 	if( s->flag.server && s->wdata_size >= 2*FIFOSIZE_SERVERLINK )