diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c index 8c1c3244d2..0ab5fe5fcf 100644 --- a/drivers/net/netdev_upperhalf.c +++ b/drivers/net/netdev_upperhalf.c @@ -270,7 +270,16 @@ static int netdev_upper_txpoll(FAR struct net_driver_s *dev) #endif pkt = netpkt_get(dev, NETPKT_TX); - ret = lower->ops->transmit(lower, pkt); + + if (netpkt_getdatalen(lower, pkt) > NETDEV_PKTSIZE(dev)) + { + nerr("ERROR: Packet too long to send!\n"); + ret = -EMSGSIZE; + } + else + { + ret = lower->ops->transmit(lower, pkt); + } if (ret != OK) { diff --git a/net/udp/udp_sendto_buffered.c b/net/udp/udp_sendto_buffered.c index da01a7bc04..18dd21c6e4 100644 --- a/net/udp/udp_sendto_buffered.c +++ b/net/udp/udp_sendto_buffered.c @@ -289,6 +289,16 @@ static int sendto_next_transfer(FAR struct udp_conn_s *conn) return -EHOSTUNREACH; } +#ifndef CONFIG_NET_IPFRAG + /* Sanity check if the packet len (with IP hdr) is greater than the MTU */ + + if (wrb->wb_iob->io_pktlen > devif_get_mtu(dev)) + { + nerr("ERROR: Packet too long to send!\n"); + return -EMSGSIZE; + } +#endif + /* If this is not the same device that we used in the last call to * udp_callback_alloc(), then we need to release and reallocate the old * callback instance.