Blame SOURCES/libvirt-virnetdevtap-Don-t-crash-on-ifname-in-virNetDevTapInterfaceStats.patch

9c6c51
From 340b09010e2c329608af82c2fbd8cb73209eb58c Mon Sep 17 00:00:00 2001
9c6c51
Message-Id: <340b09010e2c329608af82c2fbd8cb73209eb58c@dist-git>
9c6c51
From: Michal Privoznik <mprivozn@redhat.com>
9c6c51
Date: Fri, 13 Jul 2018 15:44:42 +0200
9c6c51
Subject: [PATCH] virnetdevtap: Don't crash on !ifname in
9c6c51
 virNetDevTapInterfaceStats
9c6c51
MIME-Version: 1.0
9c6c51
Content-Type: text/plain; charset=UTF-8
9c6c51
Content-Transfer-Encoding: 8bit
9c6c51
9c6c51
https://bugzilla.redhat.com/show_bug.cgi?id=1595184
9c6c51
9c6c51
Some domain <interfaces/> do not have a name (because they are
9c6c51
not TAP devices). Therefore, if
9c6c51
virNetDevTapInterfaceStats(net->ifname, ...) is called an instant
9c6c51
crash occurs. In Linux version of the function strlen() is called
9c6c51
over the name and in BSD version STREQ() is called.
9c6c51
9c6c51
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9c6c51
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
9c6c51
(cherry picked from commit 318d54e5201295239869655c2c60fb44d9d9466e)
9c6c51
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9c6c51
Reviewed-by: Ján Tomko <jtomko@redhat.com>
9c6c51
---
9c6c51
 src/util/virnetdevtap.c | 12 ++++++++++++
9c6c51
 1 file changed, 12 insertions(+)
9c6c51
9c6c51
diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
9c6c51
index bd0710ad2e..3118ca18e8 100644
9c6c51
--- a/src/util/virnetdevtap.c
9c6c51
+++ b/src/util/virnetdevtap.c
9c6c51
@@ -691,6 +691,12 @@ virNetDevTapInterfaceStats(const char *ifname,
9c6c51
     FILE *fp;
9c6c51
     char line[256], *colon;
9c6c51
 
9c6c51
+    if (!ifname) {
9c6c51
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
9c6c51
+                       _("Interface name not provided"));
9c6c51
+        return -1;
9c6c51
+    }
9c6c51
+
9c6c51
     fp = fopen("/proc/net/dev", "r");
9c6c51
     if (!fp) {
9c6c51
         virReportSystemError(errno, "%s",
9c6c51
@@ -768,6 +774,12 @@ virNetDevTapInterfaceStats(const char *ifname,
9c6c51
     struct if_data *ifd;
9c6c51
     int ret = -1;
9c6c51
 
9c6c51
+    if (!ifname) {
9c6c51
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
9c6c51
+                       _("Interface name not provided"));
9c6c51
+        return -1;
9c6c51
+    }
9c6c51
+
9c6c51
     if (getifaddrs(&ifap) < 0) {
9c6c51
         virReportSystemError(errno, "%s",
9c6c51
                              _("Could not get interface list"));
9c6c51
-- 
9c6c51
2.18.0
9c6c51