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

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