[libvirt] [PATCH v2] virnetdevtap: Don't crash on !ifname in virNetDevTapInterfaceStats

Michal Privoznik posted 1 patch 5 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/f4cfd46174e426c945ffaa3218fe8e21e629479c.1531483108.git.mprivozn@redhat.com
Test syntax-check passed
src/util/virnetdevtap.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
[libvirt] [PATCH v2] virnetdevtap: Don't crash on !ifname in virNetDevTapInterfaceStats
Posted by Michal Privoznik 5 years, 9 months ago
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>
---

diff to v1:
- changed the error message
- fixed check in BSD version

 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
--- a/src/util/virnetdevtap.c
+++ b/src/util/virnetdevtap.c
@@ -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.16.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] virnetdevtap: Don't crash on !ifname in virNetDevTapInterfaceStats
Posted by Andrea Bolognani 5 years, 9 months ago
On Fri, 2018-07-13 at 13:59 +0200, Michal Privoznik wrote:
> 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>
> ---
> 
> diff to v1:
> - changed the error message
> - fixed check in BSD version
> 
>  src/util/virnetdevtap.c | 12 ++++++++++++

Reviewed-by: Andrea Bolognani <abologna@redhat.com>

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list