Skip to content

Commit

Permalink
handle truncated data
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Aug 3, 2018
1 parent d2df2c5 commit e76c1fb
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions tun_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,13 @@ int tun_dev_client_event_loop()
}
else if(events[idx].data.u64==(u64_t)tun_fd)
{
len=read(tun_fd,data,max_data_len);
len=read(tun_fd,data,max_data_len+1);

if(len==max_data_len+1)
{
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
continue;
}

if(len<0)
{
Expand All @@ -515,7 +521,13 @@ int tun_dev_client_event_loop()
fd64_t fd64=events[idx].data.u64;
int fd=fd_manager.to_fd(fd64);

len=recv(fd,data,max_data_len,0);
len=recv(fd,data,max_data_len+1,0);

if(len==max_data_len+1)
{
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
continue;
}

if(len<0)
{
Expand Down Expand Up @@ -768,13 +780,19 @@ int tun_dev_server_event_loop()
{
struct sockaddr_in udp_new_addr_in={0};
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
if ((len = recvfrom(local_listen_fd, data, max_data_len, 0,
if ((len = recvfrom(local_listen_fd, data, max_data_len+1, 0,
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) < 0) {
mylog(log_error,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",strerror(errno));
continue;
//myexit(1);
};

if(len==max_data_len+1)
{
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
continue;
}

if(de_cook(data,len)<0)
{
mylog(log_warn,"de_cook(data,len)failed \n");
Expand Down Expand Up @@ -856,7 +874,14 @@ int tun_dev_server_event_loop()
}
else if(events[idx].data.u64==(u64_t)tun_fd)
{
len=read(tun_fd,data,max_data_len);
len=read(tun_fd,data,max_data_len+1);

if(len==max_data_len+1)
{
mylog(log_warn,"huge packet, data_len > %d,dropped\n",max_data_len);
continue;
}

if(len<0)
{
mylog(log_warn,"read from tun_fd return %d,errno=%s\n",len,strerror(errno));
Expand Down

0 comments on commit e76c1fb

Please sign in to comment.