* [PATCH 1/1] xfs: Fix Smatch warning in xfs_attr_node_get
@ 2020-07-29 0:08 Allison Collins
2020-07-29 1:23 ` Darrick J. Wong
0 siblings, 1 reply; 3+ messages in thread
From: Allison Collins @ 2020-07-29 0:08 UTC (permalink / raw)
To: linux-xfs
Fix warning: variable dereferenced before check 'state' in
xfs_attr_node_get. If xfs_attr_node_hasname fails, it may return a null
state. If state is null, do not derefrence it. Go straight to out.
Signed-off-by: Allison Collins <allison.henderson@oracle.com>
---
fs/xfs/libxfs/xfs_attr.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
index e5ec9ed..90b7b24 100644
--- a/fs/xfs/libxfs/xfs_attr.c
+++ b/fs/xfs/libxfs/xfs_attr.c
@@ -1409,6 +1409,9 @@ xfs_attr_node_get(
* Search to see if name exists, and get back a pointer to it.
*/
error = xfs_attr_node_hasname(args, &state);
+ if (!state)
+ goto out;
+
if (error != -EEXIST)
goto out_release;
@@ -1426,7 +1429,7 @@ xfs_attr_node_get(
xfs_trans_brelse(args->trans, state->path.blk[i].bp);
state->path.blk[i].bp = NULL;
}
-
+out:
if (state)
xfs_da_state_free(state);
return error;
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] xfs: Fix Smatch warning in xfs_attr_node_get
2020-07-29 0:08 [PATCH 1/1] xfs: Fix Smatch warning in xfs_attr_node_get Allison Collins
@ 2020-07-29 1:23 ` Darrick J. Wong
2020-07-29 4:37 ` Allison Collins
0 siblings, 1 reply; 3+ messages in thread
From: Darrick J. Wong @ 2020-07-29 1:23 UTC (permalink / raw)
To: Allison Collins; +Cc: linux-xfs
On Tue, Jul 28, 2020 at 05:08:53PM -0700, Allison Collins wrote:
> Fix warning: variable dereferenced before check 'state' in
> xfs_attr_node_get. If xfs_attr_node_hasname fails, it may return a null
> state. If state is null, do not derefrence it. Go straight to out.
>
> Signed-off-by: Allison Collins <allison.henderson@oracle.com>
> ---
> fs/xfs/libxfs/xfs_attr.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
> index e5ec9ed..90b7b24 100644
> --- a/fs/xfs/libxfs/xfs_attr.c
> +++ b/fs/xfs/libxfs/xfs_attr.c
> @@ -1409,6 +1409,9 @@ xfs_attr_node_get(
> * Search to see if name exists, and get back a pointer to it.
> */
> error = xfs_attr_node_hasname(args, &state);
> + if (!state)
> + goto out;
> +
> if (error != -EEXIST)
> goto out_release;
>
> @@ -1426,7 +1429,7 @@ xfs_attr_node_get(
I would've just changed the for loop to:
for (i = 0; state && i < state->path.active; i++) {
Since that way we'd know that the error-out path always does the right
thing wrt any resources that could have been allocated.
--D
> xfs_trans_brelse(args->trans, state->path.blk[i].bp);
> state->path.blk[i].bp = NULL;
> }
> -
> +out:
> if (state)
> xfs_da_state_free(state);
> return error;
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] xfs: Fix Smatch warning in xfs_attr_node_get
2020-07-29 1:23 ` Darrick J. Wong
@ 2020-07-29 4:37 ` Allison Collins
0 siblings, 0 replies; 3+ messages in thread
From: Allison Collins @ 2020-07-29 4:37 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-xfs
On 7/28/20 6:23 PM, Darrick J. Wong wrote:
> On Tue, Jul 28, 2020 at 05:08:53PM -0700, Allison Collins wrote:
>> Fix warning: variable dereferenced before check 'state' in
>> xfs_attr_node_get. If xfs_attr_node_hasname fails, it may return a null
>> state. If state is null, do not derefrence it. Go straight to out.
>>
>> Signed-off-by: Allison Collins <allison.henderson@oracle.com>
>> ---
>> fs/xfs/libxfs/xfs_attr.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
>> index e5ec9ed..90b7b24 100644
>> --- a/fs/xfs/libxfs/xfs_attr.c
>> +++ b/fs/xfs/libxfs/xfs_attr.c
>> @@ -1409,6 +1409,9 @@ xfs_attr_node_get(
>> * Search to see if name exists, and get back a pointer to it.
>> */
>> error = xfs_attr_node_hasname(args, &state);
>> + if (!state)
>> + goto out;
>> +
>> if (error != -EEXIST)
>> goto out_release;
>>
>> @@ -1426,7 +1429,7 @@ xfs_attr_node_get(
>
> I would've just changed the for loop to:
>
> for (i = 0; state && i < state->path.active; i++) {
>
> Since that way we'd know that the error-out path always does the right
> thing wrt any resources that could have been allocated.
>
Sure, will update
Allison
> --D
>
>> xfs_trans_brelse(args->trans, state->path.blk[i].bp);
>> state->path.blk[i].bp = NULL;
>> }
>> -
>> +out:
>> if (state)
>> xfs_da_state_free(state);
>> return error;
>> --
>> 2.7.4
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-29 4:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 0:08 [PATCH 1/1] xfs: Fix Smatch warning in xfs_attr_node_get Allison Collins
2020-07-29 1:23 ` Darrick J. Wong
2020-07-29 4:37 ` Allison Collins
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.