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

Richard W.M. Jones rjones at redhat.com
Fri Aug 7 11:43:53 UTC 2020


On Thu, Aug 06, 2020 at 09:23:45PM -0500, Eric Blake wrote:
> 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

ACK, we should take this patch soon.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list