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