xfs
[Top] [All Lists]

Re: [PATCH 05/11] xfsprogs: xfs_mdrestore: check bad read count in perfo

To: xfs@xxxxxxxxxxx
Subject: Re: [PATCH 05/11] xfsprogs: xfs_mdrestore: check bad read count in perform_restore
From: Eric Sandeen <sandeen@xxxxxxxxxxx>
Date: Wed, 2 Dec 2015 22:54:19 -0600
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1449055167-19936-6-git-send-email-t.vivek@xxxxxxxxxxx>
References: <1449055167-19936-1-git-send-email-t.vivek@xxxxxxxxxxx> <1449055167-19936-6-git-send-email-t.vivek@xxxxxxxxxxx>
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
On 12/2/15 5:19 AM, Vivek Trivedi wrote:
> fix error reported by coverity - Integer overflowed argument
> 
> also, add print incase of invalid read count to get more debug
> information.
> 
> Signed-off-by: Vivek Trivedi <t.vivek@xxxxxxxxxxx>
> ---
>  mdrestore/xfs_mdrestore.c |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c
> index 5764616..a87a091 100644
> --- a/mdrestore/xfs_mdrestore.c
> +++ b/mdrestore/xfs_mdrestore.c
> @@ -93,6 +93,10 @@ perform_restore(
>       block_index = (__be64 *)((char *)metablock + sizeof(xfs_metablock_t));
>       block_buffer = (char *)metablock + block_size;
>  
> +     if (block_size < sizeof(tmb))
> +             fatal("bad read count, block_size: %d, tmb size %d\n",
> +                             block_size, sizeof(tmb));
> +

block_size is block_size = 1 << tmb.mb_blocklog; where mb_blocklog is
always metablock->mb_blocklog = BBSHIFT;, so block_size is always 512.

On the other hand, sizeof(tmb) is simply 8.

There seems to be no possible path for this to be a problem, so it hardly
seems worth the printf.

Would an ASSERT(block_size >= sizeof(tmb)) make coverity happy?

-Eric


>       if (fread(block_index, block_size - sizeof(tmb), 1, src_f) != 1)
>               fatal("error reading from file: %s\n", strerror(errno));
>  
> 

<Prev in Thread] Current Thread [Next in Thread>