From: Ben Pfaff Date: Fri, 2 Dec 2011 23:22:20 +0000 (-0800) Subject: netdev-linux: Report error for truncated packets on receive. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02e83e83b4c8d88f50317ba56fec53cd6d3fb909;p=openvswitch netdev-linux: Report error for truncated packets on receive. Found by inspection. Signed-off-by: Ben Pfaff --- diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 9ff286ee..27a123cd 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -802,8 +802,11 @@ netdev_linux_recv(struct netdev *netdev_, void *data, size_t size) } for (;;) { - ssize_t retval = read(netdev->fd, data, size); - if (retval >= 0) { + ssize_t retval = recv(netdev->fd, data, size, MSG_TRUNC); + if (retval > size) { + /* Received packet was longer than supplied buffer. */ + return -EMSGSIZE; + } else if (retval >= 0) { return retval; } else if (errno != EINTR) { if (errno != EAGAIN) { diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h index 81e6c391..d5a30c80 100644 --- a/lib/netdev-provider.h +++ b/lib/netdev-provider.h @@ -172,6 +172,9 @@ struct netdev_class { * packet, otherwise a negative errno value. Returns -EAGAIN immediately * if no packet is ready to be received. * + * Returns -EMSGSIZE, and discards the packet, if the received packet is + * longer than 'size' bytes. + * * This function can only be expected to return a packet if ->listen() has * been called successfully. *