[Ocfs2-tools-devel] [PATCH RESEND] libocfs2: fix overflow when counting bytes in ocfs2_malloc_blocks

Eric Ren zren at suse.com
Thu Mar 3 17:52:44 PST 2016


On 03/03/2016 06:55 PM, Joseph Qi wrote:
> num_blocks and blksize are defined type int. It will overflow if the
> volume is large.
> So should covert it to unsigned long long first.
>
> Signed-off-by: Joseph Qi <joseph.qi at huawei.com>
Reviewed-by: Eric Ren <zren at suse.com>
> ---
>   libocfs2/memory.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libocfs2/memory.c b/libocfs2/memory.c
> index ed5c05c..d5a293a 100644
> --- a/libocfs2/memory.c
> +++ b/libocfs2/memory.c
> @@ -109,7 +109,7 @@ errcode_t ocfs2_malloc_blocks(io_channel *channel, int num_blocks,
>   	blksize = io_get_blksize(channel);
>   	if (((unsigned long long)num_blocks * blksize) > SIZE_MAX)
>   		return OCFS2_ET_NO_MEMORY;
> -	bytes = num_blocks * blksize;
> +	bytes = (unsigned long long)num_blocks * blksize;
>
>   	/*
>   	 * Older glibcs abort when they can't memalign() something.




More information about the Ocfs2-tools-devel mailing list