render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
404507
From 706f4e3526b154c4b65c242eba039a53c9386ca8 Mon Sep 17 00:00:00 2001
404507
Message-Id: <706f4e3526b154c4b65c242eba039a53c9386ca8@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
404507
index 478b3b3a6f..85b15314a9 100644
4cd28d
--- a/src/libvirt_private.syms
4cd28d
+++ b/src/libvirt_private.syms
404507
@@ -1752,6 +1752,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
404507
index 82cb36dbca..5e9bd2007a 100644
4cd28d
--- a/src/util/virfile.c
4cd28d
+++ b/src/util/virfile.c
404507
@@ -1367,6 +1367,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
404507
index 91d3186223..ea1faed2e4 100644
4cd28d
--- a/src/util/virfile.h
4cd28d
+++ b/src/util/virfile.h
404507
@@ -131,6 +131,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