diff options
author | ZhengLingyun <konghuarukhr@163.com> | 2013-07-18 16:08:06 +0800 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2013-07-18 11:13:43 -0700 |
commit | bb5c146881eb2b3d48962f89ecaa9598533a91c5 (patch) | |
tree | 33da4354e7b1c6b7a3b4b98cdf84c09bc4a06b7f /lib/netdev-linux.c | |
parent | 261bd85427ad9732dbef396e3c481e19ea9ea55a (diff) |
netdev-linux: avoid negative value cast to non-negative in comparison
I am using a userspace OVS, there is a constant ERR message in log:
"dpif_netdev|ERR|error receiving data from ovs-netdev: Message too long"
Check the code and find there is a comparison between ssize_t and size_t type in
netdev_rx_linux_recv(). It makes the negative "retval" greater than the "size".
Change the sequence of comparison to avoid negative return value cast to
a positive and become greater then a non-negative value.
Signed-off-by: ZhengLingyun <konghuarukhr@163.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/netdev-linux.c')
-rw-r--r-- | lib/netdev-linux.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 8790f14e..1f738864 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -835,10 +835,8 @@ netdev_rx_linux_recv(struct netdev_rx *rx_, void *data, size_t size) : recv(rx->fd, data, size, MSG_TRUNC)); } while (retval < 0 && errno == EINTR); - if (retval > size) { - return -EMSGSIZE; - } else if (retval >= 0) { - return retval; + if (retval >= 0) { + return retval > size ? -EMSGSIZE : retval; } else { if (errno != EAGAIN) { VLOG_WARN_RL(&rl, "error receiving Ethernet packet on %s: %s", |