[Ocfs2-tools-devel] [PATCH RESEND] libocfs2: fix overflow when counting bytes in ocfs2_malloc_blocks
Gang He
ghe at suse.com
Thu Mar 3 18:39:38 PST 2016
>>>
> 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: Gang He <ghe 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.
> --
> 1.8.4.3
More information about the Ocfs2-tools-devel
mailing list