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

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