block/vpc: check that the image has not been truncated
PATCH 1/1 block/vpc: check that the image has not been truncated
this adds a check that a dynamic VHD file has not been accidently truncated (e.g. during transfer or upload).
--- block/vpc.c | 7 +++++++ 1 file changed, 7 insertions(+)
block/vpc.c +7 -0
@@ -269,6 +269,13 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, } } +if (s->free_data_block_offset >bdrv_getlength (bs->file)) { + ret = -EINVAL ; +fprintf (stderr,"block-vpc: free_data_block_offset points after" +"the end of file. the image has been truncated.\n" ); + goto fail; + } + s->last_bitmap_offset = (int64_t )-1 ;#ifdef CACHE
Signature · 1 line
1.7.9.5
Quoted 13 lines · Peter Lieven
this adds a check that a dynamic VHD file has not been accidently truncated (e.g. during transfer or upload).
Signed-off-by Peter Lieven <[email protected]>--- block/vpc.c | 7 +++++++ 1 file changed, 7 insertions(+)block/vpc.c +0
-0
block/vpc.c static int vpc_open(BlockDriverState *bs, QDict *options, int flags, · line 275
Quoted 7 lines
block/vpc.c +4
-0@@ -269,6 +269,13 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, } } +if (s->free_data_block_offset >bdrv_getlength (bs->file)) { + ret = -EINVAL ; +fprintf (stderr,"block-vpc: free_data_block_offset points after" +"the end of file. the image has been truncated.\n" );
Why fprintf() instead of using the errp argument?
Also, s/afterthe/after the/; s/file\. the/file. The/
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 17 lines · Eric Blake
Quoted 16 lines · Peter Lieven
this adds a check that a dynamic VHD file has not been accidently truncated (e.g. during transfer or upload).
Signed-off-by Peter Lieven <[email protected]>--- block/vpc.c | 7 +++++++ 1 file changed, 7 insertions(+)block/vpc.c +0
-0@@ -269,6 +269,13 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, } }
Quoted 5 lines
block/vpc.c static int vpc_open(BlockDriverState *bs, QDict *options, int flags, · line 275
Quoted 4 lines
block/vpc.c +4
-0+if (s->free_data_block_offset >bdrv_getlength (bs->file)) { + ret = -EINVAL ; +fprintf (stderr,"block-vpc: free_data_block_offset points after" +"the end of file. the image has been truncated.\n" );Why
fprintf()instead of using the errp argument?
wasn't aware. a few lines earlier fprintf(stderr, ...) was used.
if the others are otherwise happy with the patch I will send a v2.
Peter