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

c1c534
From 706f4e3526b154c4b65c242eba039a53c9386ca8 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <706f4e3526b154c4b65c242eba039a53c9386ca8@dist-git>
c1c534
From: Paolo Bonzini <pbonzini@redhat.com>
c1c534
Date: Tue, 12 Dec 2017 16:23:40 +0100
c1c534
Subject: [PATCH] util: add virFileReadHeaderQuiet wrapper around
c1c534
 virFileReadHeaderFD
c1c534
c1c534
CVE-2017-5715
c1c534
c1c534
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 src/libvirt_private.syms |  1 +
c1c534
 src/util/virfile.c       | 19 +++++++++++++++++++
c1c534
 src/util/virfile.h       |  2 ++
c1c534
 3 files changed, 22 insertions(+)
c1c534
c1c534
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
c1c534
index 478b3b3a6f..85b15314a9 100644
c1c534
--- a/src/libvirt_private.syms
c1c534
+++ b/src/libvirt_private.syms
c1c534
@@ -1752,6 +1752,7 @@ virFileReadAll;
c1c534
 virFileReadAllQuiet;
c1c534
 virFileReadBufQuiet;
c1c534
 virFileReadHeaderFD;
c1c534
+virFileReadHeaderQuiet;
c1c534
 virFileReadLimFD;
c1c534
 virFileReadLink;
c1c534
 virFileReadValueBitmap;
c1c534
diff --git a/src/util/virfile.c b/src/util/virfile.c
c1c534
index 82cb36dbca..5e9bd2007a 100644
c1c534
--- a/src/util/virfile.c
c1c534
+++ b/src/util/virfile.c
c1c534
@@ -1367,6 +1367,25 @@ virFileReadHeaderFD(int fd, int maxlen, char **buf)
c1c534
 }
c1c534
 
c1c534
 
c1c534
+int
c1c534
+virFileReadHeaderQuiet(const char *path,
c1c534
+                       int maxlen,
c1c534
+                       char **buf)
c1c534
+{
c1c534
+    int fd;
c1c534
+    int len;
c1c534
+
c1c534
+    fd = open(path, O_RDONLY);
c1c534
+    if (fd < 0)
c1c534
+        return -1;
c1c534
+
c1c534
+    len = virFileReadHeaderFD(fd, maxlen, buf);
c1c534
+    VIR_FORCE_CLOSE(fd);
c1c534
+
c1c534
+    return len;
c1c534
+}
c1c534
+
c1c534
+
c1c534
 /* A wrapper around saferead_lim that maps a failure due to
c1c534
    exceeding the maximum size limitation to EOVERFLOW.  */
c1c534
 int
c1c534
diff --git a/src/util/virfile.h b/src/util/virfile.h
c1c534
index 91d3186223..ea1faed2e4 100644
c1c534
--- a/src/util/virfile.h
c1c534
+++ b/src/util/virfile.h
c1c534
@@ -131,6 +131,8 @@ int virFileDeleteTree(const char *dir);
c1c534
 
c1c534
 int virFileReadHeaderFD(int fd, int maxlen, char **buf)
c1c534
     ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(3);
c1c534
+int virFileReadHeaderQuiet(const char *path, int maxlen, char **buf)
c1c534
+    ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
c1c534
 int virFileReadLimFD(int fd, int maxlen, char **buf)
c1c534
     ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(3);
c1c534
 int virFileReadAll(const char *path, int maxlen, char **buf)
c1c534
-- 
c1c534
2.15.1
c1c534