From 49a6a1636f849eba12fb444651ee818628426f0d Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Fri, 15 Jan 2010 19:24:53 -0500 Subject: [PATCH] netdev-linux: Avoid potential issues with unset FD. Never close the file descriptor if it is 0, since it is never a valid FD in this context. Also initialize the FD to -1 so that it is never set to a valid but incorrect value. --- lib/netdev-linux.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 85ef62a3..f2a6a5d0 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -812,6 +812,7 @@ netdev_linux_open(struct netdev_dev *netdev_dev_, int ethertype, /* Allocate network device. */ netdev = xzalloc(sizeof *netdev); + netdev->fd = -1; netdev_init(&netdev->netdev, netdev_dev_); error = netdev_get_flags(&netdev->netdev, &flags); @@ -868,8 +869,6 @@ netdev_linux_open(struct netdev_dev *netdev_dev_, int ethertype, if (error) { goto error; } - } else { - netdev->fd = -1; } *netdevp = &netdev->netdev; @@ -886,7 +885,7 @@ netdev_linux_close(struct netdev *netdev_) { struct netdev_linux *netdev = netdev_linux_cast(netdev_); - if (netdev->fd >= 0 && strcmp(netdev_get_type(netdev_), "tap")) { + if (netdev->fd > 0 && strcmp(netdev_get_type(netdev_), "tap")) { close(netdev->fd); } free(netdev); -- 2.30.2