Browse Source

Add bigness to buffers to prevent overflow on high traffic (Mac tap).

Adam Ierymenko 6 years ago
parent
commit
d77846dcea
2 changed files with 15 additions and 5 deletions
  1. 9 3
      osdep/MacEthernetTap.cpp
  2. 6 2
      osdep/MacEthernetTapAgent.c

+ 9 - 3
osdep/MacEthernetTap.cpp

@@ -350,10 +350,14 @@ void MacEthernetTap::setMtu(unsigned int mtu)
 	_mtu = mtu;
 	_mtu = mtu;
 }
 }
 
 
+#define ZT_MACETHERNETTAP_AGENT_READ_BUF_SIZE 1048576
+
 void MacEthernetTap::threadMain()
 void MacEthernetTap::threadMain()
 	throw()
 	throw()
 {
 {
-	char agentReadBuf[262144];
+	char *const agentReadBuf = (char *)valloc(ZT_MACETHERNETTAP_AGENT_READ_BUF_SIZE);
+	if (!agentReadBuf)
+		return;
 	fd_set readfds,nullfds;
 	fd_set readfds,nullfds;
 	MAC to,from;
 	MAC to,from;
 
 
@@ -375,7 +379,7 @@ void MacEthernetTap::threadMain()
 			break;
 			break;
 		}
 		}
 		if (FD_ISSET(_agentStdout,&readfds)) {
 		if (FD_ISSET(_agentStdout,&readfds)) {
-			long n = (long)read(_agentStdout,agentReadBuf + agentReadPtr,sizeof(agentReadBuf) - agentReadPtr);
+			long n = (long)read(_agentStdout,agentReadBuf + agentReadPtr,ZT_MACETHERNETTAP_AGENT_READ_BUF_SIZE - agentReadPtr);
 			if (n > 0) {
 			if (n > 0) {
 				agentReadPtr += n;
 				agentReadPtr += n;
 				while (agentReadPtr >= 2) {
 				while (agentReadPtr >= 2) {
@@ -401,9 +405,11 @@ void MacEthernetTap::threadMain()
 			}
 			}
 		}
 		}
 		if (FD_ISSET(_agentStderr,&readfds)) {
 		if (FD_ISSET(_agentStderr,&readfds)) {
-			read(_agentStderr,agentReadBuf,sizeof(agentReadBuf));
+			read(_agentStderr,agentReadBuf,ZT_MACETHERNETTAP_AGENT_READ_BUF_SIZE);
 		}
 		}
 	}
 	}
+
+	free(agentReadBuf);
 }
 }
 
 
 } // namespace ZeroTier
 } // namespace ZeroTier

+ 6 - 2
osdep/MacEthernetTapAgent.c

@@ -104,8 +104,8 @@
 
 
 #define P_IFCONFIG "/sbin/ifconfig"
 #define P_IFCONFIG "/sbin/ifconfig"
 
 
-static unsigned char s_pktReadBuf[262144] __attribute__ ((__aligned__(16)));
-static unsigned char s_stdinReadBuf[262144] __attribute__ ((__aligned__(16)));
+static unsigned char s_pktReadBuf[1048576] __attribute__ ((__aligned__(16)));
+static unsigned char s_stdinReadBuf[1048576] __attribute__ ((__aligned__(16)));
 static char s_deviceName[IFNAMSIZ];
 static char s_deviceName[IFNAMSIZ];
 static char s_peerDeviceName[IFNAMSIZ];
 static char s_peerDeviceName[IFNAMSIZ];
 static int s_bpffd = -1;
 static int s_bpffd = -1;
@@ -418,6 +418,10 @@ int main(int argc,char **argv)
 
 
 								case ZT_MACETHERNETTAPAGENT_STDIN_CMD_EXIT:
 								case ZT_MACETHERNETTAPAGENT_STDIN_CMD_EXIT:
 									return ZT_MACETHERNETTAPAGENT_EXIT_CODE_SUCCESS;
 									return ZT_MACETHERNETTAPAGENT_EXIT_CODE_SUCCESS;
+
+								default:
+									fprintf(stderr,"E unrecognized message type over pipe from host process: %d (length: %d)\n",(int)msg[0],(int)len);
+									break;
 							}
 							}
 						}
 						}