[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [libnbd PATCH] info: Keep request within 4G bound



On Fri, Oct 16, 2020 at 11:35:55PM -0500, Eric Blake wrote:
> Otherwise, we get a failure due to Numerical result out of range.
> 
> And for safety's sake, we are best capping our request to an aligned
> value, if the server insists on minimum alignment.
> 
> Fixes: f3fd935c
> ---
>  info/nbdinfo.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/info/nbdinfo.c b/info/nbdinfo.c
> index 1afdf98..2b22f51 100644
> --- a/info/nbdinfo.c
> +++ b/info/nbdinfo.c
> @@ -31,6 +31,8 @@
> 
>  #include <libnbd.h>
> 
> +#define MIN(a,b) ((a) < (b) ? (a) : (b))

I suppose we could import the min & max macros from nbdkit
common/include/minmax.h.  However that's a larger change.

>  static const char *progname;
>  static FILE *fp;
>  static bool list_all = false;
> @@ -267,7 +269,7 @@ main (int argc, char *argv[])
>      fprintf (fp, "%" PRIi64 "\n", size);
>    }
>    else if (map) {               /* --map (!list_all) */
> -    uint64_t offset, prev_offset;
> +    uint64_t offset, prev_offset, align, max_len;
> 
>      /* Did we get the requested map? */
>      if (!nbd_can_meta_context (nbd, map)) {
> @@ -276,6 +278,8 @@ main (int argc, char *argv[])
>                 progname, map);
>        exit (EXIT_FAILURE);
>      }
> +    align = nbd_get_block_size (nbd, LIBNBD_SIZE_MINIMUM) ?: 512;
> +    max_len = UINT32_MAX - align + 1;
> 
>      size = nbd_get_size (nbd);
>      if (size == -1) {
> @@ -286,7 +290,7 @@ main (int argc, char *argv[])
>      if (json_output) fprintf (fp, "[\n");
>      for (offset = 0; offset < size;) {
>        prev_offset = offset;
> -      if (nbd_block_status (nbd, size - offset, offset,
> +      if (nbd_block_status (nbd, MIN (size - offset, max_len), offset,
>                              (nbd_extent_callback) { .callback = extent_callback,
>                                                      .user_data = &offset },
>                              0) == -1) {
> -- 
> 2.29.0.rc1

ACK

Thanks,

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]