Discard a packet that exceeds the receive buffer
authorMartin Willi <martin@revosec.ch>
Wed, 11 Aug 2010 08:51:40 +0000 (10:51 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 11 Aug 2010 08:52:59 +0000 (10:52 +0200)
src/libcharon/plugins/socket_default/socket_default_socket.c
src/libcharon/plugins/socket_dynamic/socket_dynamic_socket.c
src/libcharon/plugins/socket_raw/socket_raw_socket.c

index c88206e..4eeffff 100644 (file)
@@ -212,6 +212,11 @@ METHOD(socket_t, receiver, status_t,
                        DBG1(DBG_NET, "error reading socket: %s", strerror(errno));
                        return FAILED;
                }
+               if (msg.msg_flags & MSG_TRUNC)
+               {
+                       DBG1(DBG_NET, "receive buffer too small, packet discarded");
+                       return FAILED;
+               }
                DBG3(DBG_NET, "received packet %b", buffer, bytes_read);
 
                if (bytes_read < MARKER_LEN)
index 42921d6..35fbb3a 100644 (file)
@@ -229,6 +229,11 @@ static packet_t *receive_packet(private_socket_dynamic_socket_t *this,
                DBG1(DBG_NET, "error reading socket: %s", strerror(errno));
                return NULL;
        }
+       if (msg.msg_flags & MSG_TRUNC)
+       {
+               DBG1(DBG_NET, "receive buffer too small, packet discarded");
+               return NULL;
+       }
        DBG3(DBG_NET, "received packet %b", buffer, len);
 
        if (len < MARKER_LEN)
index 604a9d9..6cbab84 100644 (file)
@@ -172,6 +172,11 @@ METHOD(socket_t, receiver, status_t,
                        DBG1(DBG_NET, "error reading from IPv4 socket: %s", strerror(errno));
                        return FAILED;
                }
+               if (bytes_read == this->max_packet)
+               {
+                       DBG1(DBG_NET, "receive buffer too small, packet discarded");
+                       return FAILED;
+               }
                DBG3(DBG_NET, "received IPv4 packet %b", buffer, bytes_read);
 
                /* read source/dest from raw IP/UDP header */