From cf44e028d076399177619d8bc523fa13521e0b5e Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 19 Jan 2009 23:21:30 +0000 Subject: fixed silly bug at new tundevice --- src/anytun.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/anytun.cpp') diff --git a/src/anytun.cpp b/src/anytun.cpp index 1886a60..3a1ab73 100644 --- a/src/anytun.cpp +++ b/src/anytun.cpp @@ -168,7 +168,12 @@ void sender(void* p) encrypted_packet.setLength(MAX_PACKET_LENGTH); // read packet from device - u_int32_t len = param->dev.read(plain_packet.getPayload(), plain_packet.getPayloadLength()); + int len = param->dev.read(plain_packet.getPayload(), plain_packet.getPayloadLength()); + if(len < 0) + continue; // silently ignore device read errors, this is probably no good idea... + + if(static_cast(len) < PlainPacket::getHeaderLength()) + continue; // ignore short packets plain_packet.setPayloadLength(len); // set payload type if(param->dev.getType() == TYPE_TUN) @@ -257,8 +262,11 @@ void receiver(void* p) encrypted_packet.setLength(MAX_PACKET_LENGTH); // read packet from socket - u_int32_t len = param->src.recv(encrypted_packet.getBuf(), encrypted_packet.getLength(), remote_end); - if(len < EncryptedPacket::getHeaderLength()) + int len = param->src.recv(encrypted_packet.getBuf(), encrypted_packet.getLength(), remote_end); + if(len < 0) + continue; // silently ignore socket recv errors, this is probably no good idea... + + if(static_cast(len) < EncryptedPacket::getHeaderLength()) continue; // ignore short packets encrypted_packet.setLength(len); @@ -319,7 +327,7 @@ void receiver(void* p) } catch(std::runtime_error& e) { - cLog.msg(Log::PRIO_ERR) << "sender thread died due to an uncaught runtime_error: " << e.what(); + cLog.msg(Log::PRIO_ERR) << "receiver thread died due to an uncaught runtime_error: " << e.what(); } catch(std::exception& e) { -- cgit v1.2.3