Blame SOURCES/0042-sparsify-Prevent-overwriting-block-or-char-output-de.patch

cd6068
From 05d53de9cdc06a5c822b13aed9cae6ce9a278e09 Mon Sep 17 00:00:00 2001
cd6068
From: "Richard W.M. Jones" <rjones@redhat.com>
cd6068
Date: Wed, 22 Jan 2014 13:10:08 +0000
cd6068
Subject: [PATCH] sparsify: Prevent overwriting block or char output devices
cd6068
 (RHBZ#1056290).
cd6068
cd6068
virt-sparsify doesn't work if the output is a block device, and cannot
cd6068
possibly work if the output is a char device.  Currently if you try
cd6068
this it actually overwrites (deletes) the output device which is not
cd6068
exactly desirable.  Therefore throw an error and exit.
cd6068
cd6068
Cherry picked from commit 13bca32e4ec9213e69ea55e837dea846719fb67e.
cd6068
Added additional supporting functions is_block_device and
cd6068
is_char_device from upstream.
cd6068
---
cd6068
 sparsify/sparsify.ml | 17 +++++++++++++++++
cd6068
 1 file changed, 17 insertions(+)
cd6068
cd6068
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml
cd6068
index 659d46f..d2f5347 100644
cd6068
--- a/sparsify/sparsify.ml
cd6068
+++ b/sparsify/sparsify.ml
cd6068
@@ -151,6 +151,23 @@ read the man page virt-sparsify(1).
cd6068
   if contains_colon outdisk then
cd6068
     error (f_"output filename '%s' contains a colon (':'); qemu-img command line syntax prevents us from using such an image") outdisk;
cd6068
 
cd6068
+  (* Check the output is not a block or char special (RHBZ#1056290). *)
cd6068
+  let is_block_device file =
cd6068
+    try (Unix.stat file).Unix.st_kind = Unix.S_BLK
cd6068
+    with Unix.Unix_error _ -> false
cd6068
+  and is_char_device file =
cd6068
+    try (Unix.stat file).Unix.st_kind = Unix.S_CHR
cd6068
+    with Unix.Unix_error _ -> false
cd6068
+  in
cd6068
+
cd6068
+  if is_block_device outdisk then
cd6068
+    error (f_"output '%s' cannot be a block device, it must be a regular file")
cd6068
+      outdisk;
cd6068
+
cd6068
+  if is_char_device outdisk then
cd6068
+    error (f_"output '%s' cannot be a character device, it must be a regular file")
cd6068
+      outdisk;
cd6068
+
cd6068
   indisk, outdisk, compress, convert,
cd6068
     debug_gc, format, ignores, machine_readable,
cd6068
     option, quiet, verbose, trace, zeroes
cd6068
-- 
cd6068
1.8.3.1
cd6068