Re: [PATCH v2 06/15] util: Modify the FileTypeInfo to add a version size

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

 



On Thu, Jun 23, 2016 at 13:29:02 -0400, John Ferlan wrote:
> The version field historically has been a 4 byte data; however, an upcoming
> new type will use a 2 byte version.  So let's adjust for that now.
> 
> Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
> ---
>  src/util/virstoragefile.c | 60 +++++++++++++++++++++++++++++------------------
>  1 file changed, 37 insertions(+), 23 deletions(-)
> 
> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
> index de4955b..37e9798 100644
> --- a/src/util/virstoragefile.c
> +++ b/src/util/virstoragefile.c
> @@ -1,7 +1,7 @@
>  /*
>   * virstoragefile.c: file utility functions for FS storage backend
>   *
> - * Copyright (C) 2007-2014 Red Hat, Inc.
> + * Copyright (C) 2007-2014, 2016 Red Hat, Inc.
>   * Copyright (C) 2007-2008 Daniel P. Berrange
>   *
>   * This library is free software; you can redistribute it and/or
> @@ -120,10 +120,12 @@ struct FileTypeInfo {
>                           * to check at head of file */
>      const char *extension; /* Optional file extension to check */
>      enum lv_endian endian; /* Endianness of file format */
> +
>      int versionOffset;    /* Byte offset from start of file
>                             * where we find version number,
>                             * -1 to always fail the version test,
>                             * -2 to always pass the version test */
> +    int versionSize;      /* Size in bytes of version data (0, 2, or 4) */

If the size is 0 ...

>      int versionNumbers[FILE_TYPE_VERSIONS_LAST];
>                            /* Version numbers to validate. Zeroes are ignored. */
>      int sizeOffset;       /* Byte offset from start of file

[...]

> @@ -635,13 +637,25 @@ virStorageFileMatchesVersion(int format,
>      if (fileTypeInfo[format].versionOffset == -2)
>          return true;
>  
> -    if ((fileTypeInfo[format].versionOffset + 4) > buflen)
> +    if ((fileTypeInfo[format].versionOffset +
> +         fileTypeInfo[format].versionSize) > buflen)
>          return false;
>  
> -    if (fileTypeInfo[format].endian == LV_LITTLE_ENDIAN)
> -        version = virReadBufInt32LE(buf + fileTypeInfo[format].versionOffset);
> -    else
> -        version = virReadBufInt32BE(buf + fileTypeInfo[format].versionOffset);
> +    if (fileTypeInfo[format].endian == LV_LITTLE_ENDIAN) {

... code below shouldn't be executed at all.

> +        if (fileTypeInfo[format].versionSize == 4)
> +            version = virReadBufInt32LE(buf +
> +                                        fileTypeInfo[format].versionOffset);
> +        else
> +            version = virReadBufInt16LE(buf +
> +                                        fileTypeInfo[format].versionOffset);
> +    } else {
> +        if (fileTypeInfo[format].versionSize == 4)
> +            version = virReadBufInt32BE(buf +
> +                                        fileTypeInfo[format].versionOffset);
> +        else
> +            version = virReadBufInt16BE(buf +
> +                                        fileTypeInfo[format].versionOffset);
> +    }

ACK with the change.

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]