[Ocfs2-tools-devel] [PATCH] tunefs.ocfs2: fix a potential overflowing problem in check_new_size

piaojun piaojun at huawei.com
Tue May 24 19:56:17 PDT 2016



On 2016-5-25 9:01, Joseph Qi wrote:
> Hi Jun,
> IMO,in this case, it will 100% overflow, not potential, am I right?
> 
> Thanks,
> Joseph
> 
Yes, thanks for reviewing!
> On 2016/5/24 22:24, piaojun wrote:
>> Potentially overflowing expression "0xffffffffU << b_to_c_bits" with
>> type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit
>> arithmetic before being used in a context which expects an expression
>> of type "uint64_t" (64 bits, unsigned). To avoid overflow, cast the left
>> operand to "uint64_t" before performing the left shift.
>>
>> Fixes: 15f01d8d8c1c ("tunefs.ocfs2: Warn if not using complete device")
>>
>> Signed-off-by: Jun Piao <piaojun at huawei.com>
>> ---
>>  tunefs.ocfs2/op_resize_volume.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tunefs.ocfs2/op_resize_volume.c b/tunefs.ocfs2/op_resize_volume.c
>> index 076bda0..84d8628 100644
>> --- a/tunefs.ocfs2/op_resize_volume.c
>> +++ b/tunefs.ocfs2/op_resize_volume.c
>> @@ -543,7 +543,7 @@ static errcode_t check_new_size(ocfs2_filesys *fs, uint64_t new_size,
>>  				 "Clusters (%"PRIu64" is greater than "
>>  				 "maximum possible clusters %"PRIu32"\n",
>>  				 device_clusters, UINT32_MAX);
>> -			try_blocks = UINT32_MAX << b_to_c_bits;
>> +			try_blocks = (uint64_t)UINT32_MAX << b_to_c_bits;
>>  			errorf("Clusters %"PRIu64" is greater than max allowed"
>>  			       " %"PRIu32".\nIf you want to resize to %"PRIu64
>>  			       " blocks please specify %"PRIu64" as "
>>
> 
> 
> 
> .
> 




More information about the Ocfs2-tools-devel mailing list