You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

From f3304710b72de55249ef461c544edffd5705bdc7 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 1 May 2017 14:42:25 -0400
Subject: [PATCH 05/22] make_mac_path(): fix leaked file descriptor.
When make_mac_path() gets an error from efidp_make_mac_addr(), it fails
to close the file descriptor to the network device. So close it. Also
ensure that the ifrn_name field is NUL terminated.
Found by covscan.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/linux.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/linux.c b/src/linux.c
index 34ed479..3c77a93 100644
--- a/src/linux.c
+++ b/src/linux.c
@@ -1035,6 +1035,7 @@ make_mac_path(uint8_t *buf, ssize_t size, const char * const ifname)
memset(&ifr, 0, sizeof (ifr));
strncpy(ifr.ifr_name, ifname, IF_NAMESIZE);
+ ifr.ifr_name[IF_NAMESIZE-1] = '\0';
drvinfo.cmd = ETHTOOL_GDRVINFO;
ifr.ifr_data = (caddr_t)&drvinfo;
@@ -1062,7 +1063,8 @@ make_mac_path(uint8_t *buf, ssize_t size, const char * const ifname)
(uint8_t *)ifr.ifr_ifru.ifru_hwaddr.sa_data,
sizeof(ifr.ifr_ifru.ifru_hwaddr.sa_data));
if (sz < 0)
- return -1;
+ goto err;
+
off += sz;
ret = off;
err:
--
2.12.2