Patchwork [v3,03/10] vmdk: use unsigned values for on disk header fields

login
register
mail settings
Submitter Fam Zheng
Date Aug. 6, 2013, 1:40 a.m.
Message ID <1375753243-19530-4-git-send-email-famz@redhat.com>
Download mbox | patch
Permalink /patch/264829/
State New
Headers show

Comments

Fam Zheng - Aug. 6, 2013, 1:40 a.m.
The size and offset fields are all non-negative values, use uint64_t for
them to avoid getting negative in memory value by int overflow.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/vmdk.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
Jeff Cody - Aug. 6, 2013, 3:30 a.m.
On Tue, Aug 06, 2013 at 09:40:36AM +0800, Fam Zheng wrote:
> The size and offset fields are all non-negative values, use uint64_t for
> them to avoid getting negative in memory value by int overflow.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/vmdk.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index 7ebe36b..976b871 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -67,14 +67,14 @@ typedef struct {
>  typedef struct {
>      uint32_t version;
>      uint32_t flags;
> -    int64_t capacity;
> -    int64_t granularity;
> -    int64_t desc_offset;
> -    int64_t desc_size;
> -    int32_t num_gtes_per_gte;
> -    int64_t rgd_offset;
> -    int64_t gd_offset;
> -    int64_t grain_offset;
> +    uint64_t capacity;
> +    uint64_t granularity;
> +    uint64_t desc_offset;

desc_offset in BDRVVmdkState should be uint64_t as well, right?

> +    uint64_t desc_size;
> +    uint32_t num_gtes_per_gte;
> +    uint64_t rgd_offset;
> +    uint64_t gd_offset;
> +    uint64_t grain_offset;
>      char filler[1];
>      char check_bytes[4];
>      uint16_t compressAlgorithm;
> -- 
> 1.8.3.4
>
Fam Zheng - Aug. 6, 2013, 3:42 a.m.
On Mon, 08/05 23:30, Jeff Cody wrote:
> On Tue, Aug 06, 2013 at 09:40:36AM +0800, Fam Zheng wrote:
> > The size and offset fields are all non-negative values, use uint64_t for
> > them to avoid getting negative in memory value by int overflow.
> > 
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> >  block/vmdk.c | 16 ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> > 
> > diff --git a/block/vmdk.c b/block/vmdk.c
> > index 7ebe36b..976b871 100644
> > --- a/block/vmdk.c
> > +++ b/block/vmdk.c
> > @@ -67,14 +67,14 @@ typedef struct {
> >  typedef struct {
> >      uint32_t version;
> >      uint32_t flags;
> > -    int64_t capacity;
> > -    int64_t granularity;
> > -    int64_t desc_offset;
> > -    int64_t desc_size;
> > -    int32_t num_gtes_per_gte;
> > -    int64_t rgd_offset;
> > -    int64_t gd_offset;
> > -    int64_t grain_offset;
> > +    uint64_t capacity;
> > +    uint64_t granularity;
> > +    uint64_t desc_offset;
> 
> desc_offset in BDRVVmdkState should be uint64_t as well, right?

Yes, will fix.
> 
> > +    uint64_t desc_size;
> > +    uint32_t num_gtes_per_gte;
> > +    uint64_t rgd_offset;
> > +    uint64_t gd_offset;
> > +    uint64_t grain_offset;
> >      char filler[1];
> >      char check_bytes[4];
> >      uint16_t compressAlgorithm;
> > -- 
> > 1.8.3.4
> >

Patch

diff --git a/block/vmdk.c b/block/vmdk.c
index 7ebe36b..976b871 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -67,14 +67,14 @@  typedef struct {
 typedef struct {
     uint32_t version;
     uint32_t flags;
-    int64_t capacity;
-    int64_t granularity;
-    int64_t desc_offset;
-    int64_t desc_size;
-    int32_t num_gtes_per_gte;
-    int64_t rgd_offset;
-    int64_t gd_offset;
-    int64_t grain_offset;
+    uint64_t capacity;
+    uint64_t granularity;
+    uint64_t desc_offset;
+    uint64_t desc_size;
+    uint32_t num_gtes_per_gte;
+    uint64_t rgd_offset;
+    uint64_t gd_offset;
+    uint64_t grain_offset;
     char filler[1];
     char check_bytes[4];
     uint16_t compressAlgorithm;