Re: [PATCH] fs: fix a bug when new_insert_key is not initialization
From: zhong jiang
Date: Mon Aug 01 2016 - 22:28:53 EST
On 2016/8/2 7:05, Andrew Morton wrote:
> On Sat, 30 Jul 2016 11:51:09 +0800 zhongjiang <zhongjiang@xxxxxxxxxx> wrote:
>
>> From: zhong jiang <zhongjiang@xxxxxxxxxx>
>>
>> when compile the kenrel code, I happens to the following warn.
>> fs/reiserfs/ibalance.c:1156:2: warning: ___new_insert_key___ may be used
>> uninitialized in this function.
>> memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);
>>
>> The patch fix it by check the new_insert_ptr. if new_insert_ptr is not
>> NULL, we ensure that new_insert_key is assigned. therefore, memcpy will
>> saftly exec the operatetion.
>>
>> --- a/fs/reiserfs/ibalance.c
>> +++ b/fs/reiserfs/ibalance.c
>> @@ -1153,8 +1153,10 @@ int balance_internal(struct tree_balance *tb,
>> insert_ptr);
>> }
>>
>> - memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);
>> - insert_ptr[0] = new_insert_ptr;
>> + if (new_insert_ptr) {
>> + memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);
>> + insert_ptr[0] = new_insert_ptr;
>> + }
>>
>> return order;
> Jeff has aleady fixed this with an equivalent patch. It's in -mm at
> present.
>
> From: Jeff Mahoney <jeffm@xxxxxxxx>
> Subject: reiserfs: fix "new_insert_key may be used uninitialized ..."
>
> new_insert_key only makes any sense when it's associated with a
> new_insert_ptr, which is initialized to NULL and changed to a buffer_head
> when we also initialize new_insert_key. We can key off of that to avoid
> the uninitialized warning.
>
> Link: http://lkml.kernel.org/r/5eca5ffb-2155-8df2-b4a2-f162f105efed@xxxxxxxx
> Signed-off-by: Jeff Mahoney <jeffm@xxxxxxxx>
> Cc: Arnd Bergmann <arnd@xxxxxxxx>
> Cc: Jan Kara <jack@xxxxxxx>
> Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> ---
>
> fs/reiserfs/ibalance.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff -puN fs/reiserfs/ibalance.c~reiserfs-fix-new_insert_key-may-be-used-uninitialized fs/reiserfs/ibalance.c
> --- a/fs/reiserfs/ibalance.c~reiserfs-fix-new_insert_key-may-be-used-uninitialized
> +++ a/fs/reiserfs/ibalance.c
> @@ -1153,8 +1153,9 @@ int balance_internal(struct tree_balance
> insert_ptr);
> }
>
> - memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);
> insert_ptr[0] = new_insert_ptr;
> + if (new_insert_ptr)
> + memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);
>
> return order;
> }
> _
>
>
> .
>
ok , I did not notice. thanks.