Blame SOURCES/libvirt-util-add-virFileReadHeaderQuiet-wrapper-around-virFileReadHeaderFD.patch

4cd28d
From da15d67c5cf0b6c0c1974d8ca251dbeec3d6a964 Mon Sep 17 00:00:00 2001
4cd28d
Message-Id: <da15d67c5cf0b6c0c1974d8ca251dbeec3d6a964@dist-git>
4cd28d
From: Paolo Bonzini <pbonzini@redhat.com>
4cd28d
Date: Tue, 12 Dec 2017 16:23:40 +0100
4cd28d
Subject: [PATCH] util: add virFileReadHeaderQuiet wrapper around
4cd28d
 virFileReadHeaderFD
4cd28d
4cd28d
CVE-2017-5715
4cd28d
4cd28d
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4cd28d
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
4cd28d
---
4cd28d
 src/libvirt_private.syms |  1 +
4cd28d
 src/util/virfile.c       | 19 +++++++++++++++++++
4cd28d
 src/util/virfile.h       |  2 ++
4cd28d
 3 files changed, 22 insertions(+)
4cd28d
4cd28d
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
4cd28d
index 62ebb8180e..0c972d1861 100644
4cd28d
--- a/src/libvirt_private.syms
4cd28d
+++ b/src/libvirt_private.syms
4cd28d
@@ -1646,6 +1646,7 @@ virFileReadAll;
4cd28d
 virFileReadAllQuiet;
4cd28d
 virFileReadBufQuiet;
4cd28d
 virFileReadHeaderFD;
4cd28d
+virFileReadHeaderQuiet;
4cd28d
 virFileReadLimFD;
4cd28d
 virFileReadLink;
4cd28d
 virFileReadValueBitmap;
4cd28d
diff --git a/src/util/virfile.c b/src/util/virfile.c
4cd28d
index a91c2c3495..51d1f5ce66 100644
4cd28d
--- a/src/util/virfile.c
4cd28d
+++ b/src/util/virfile.c
4cd28d
@@ -1356,6 +1356,25 @@ virFileReadHeaderFD(int fd, int maxlen, char **buf)
4cd28d
 }
4cd28d
 
4cd28d
 
4cd28d
+int
4cd28d
+virFileReadHeaderQuiet(const char *path,
4cd28d
+                       int maxlen,
4cd28d
+                       char **buf)
4cd28d
+{
4cd28d
+    int fd;
4cd28d
+    int len;
4cd28d
+
4cd28d
+    fd = open(path, O_RDONLY);
4cd28d
+    if (fd < 0)
4cd28d
+        return -1;
4cd28d
+
4cd28d
+    len = virFileReadHeaderFD(fd, maxlen, buf);
4cd28d
+    VIR_FORCE_CLOSE(fd);
4cd28d
+
4cd28d
+    return len;
4cd28d
+}
4cd28d
+
4cd28d
+
4cd28d
 /* A wrapper around saferead_lim that maps a failure due to
4cd28d
    exceeding the maximum size limitation to EOVERFLOW.  */
4cd28d
 int
4cd28d
diff --git a/src/util/virfile.h b/src/util/virfile.h
4cd28d
index ba1c57c06a..38cc23ecaa 100644
4cd28d
--- a/src/util/virfile.h
4cd28d
+++ b/src/util/virfile.h
4cd28d
@@ -129,6 +129,8 @@ int virFileDeleteTree(const char *dir);
4cd28d
 
4cd28d
 int virFileReadHeaderFD(int fd, int maxlen, char **buf)
4cd28d
     ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(3);
4cd28d
+int virFileReadHeaderQuiet(const char *path, int maxlen, char **buf)
4cd28d
+    ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
4cd28d
 int virFileReadLimFD(int fd, int maxlen, char **buf)
4cd28d
     ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(3);
4cd28d
 int virFileReadAll(const char *path, int maxlen, char **buf)
4cd28d
-- 
4cd28d
2.15.1
4cd28d