[Libguestfs] [nbdkit PATCH 1/4] file: Forbid non-regular, non-block file names

Eric Blake eblake at redhat.com
Fri Aug 7 02:23:45 UTC 2020


Serving a directory, char device, fifo, socket, or other unusual file
type is likely to cause unusual problems down the road when trying to
use .pread; let's move the failure sooner to .open.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 plugins/file/file.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/plugins/file/file.c b/plugins/file/file.c
index dc99f992..e049864a 100644
--- a/plugins/file/file.c
+++ b/plugins/file/file.c
@@ -189,7 +189,16 @@ file_open (int readonly)
     return NULL;
   }

-  h->is_block_device = S_ISBLK (statbuf.st_mode);
+  if (S_ISBLK (statbuf.st_mode))
+    h->is_block_device = true;
+  else if (S_ISREG (statbuf.st_mode))
+    h->is_block_device = false;
+  else {
+    nbdkit_error ("file is not regular or block device: %s", filename);
+    close (h->fd);
+    free (h);
+    return NULL;
+  }
   h->sector_size = 4096;  /* Start with safe guess */

 #ifdef BLKSSZGET
-- 
2.28.0




More information about the Libguestfs mailing list