Linux-XFS Archive on lore.kernel.org
 help / color / Atom feed
* [bug report] xfs: Add xfs_has_attr and subroutines
@ 2020-07-28 11:57 dan.carpenter
  2020-07-28 17:49 ` Allison Collins
  0 siblings, 1 reply; 2+ messages in thread
From: dan.carpenter @ 2020-07-28 11:57 UTC (permalink / raw)
  To: allison.henderson; +Cc: linux-xfs

Hello Allison Collins,

The patch cfe3d8821c6f: "xfs: Add xfs_has_attr and subroutines" from
Jul 20, 2020, leads to the following Smatch warning:

	fs/xfs/libxfs/xfs_attr.c:1431 xfs_attr_node_get()
	warn: variable dereferenced before check 'state' (see line 1426)

fs/xfs/libxfs/xfs_attr.c
  1398  STATIC int
  1399  xfs_attr_node_get(
  1400          struct xfs_da_args      *args)
  1401  {
  1402          struct xfs_da_state     *state;
  1403          struct xfs_da_state_blk *blk;
  1404          int                     i;
  1405          int                     error;
  1406  
  1407          trace_xfs_attr_node_get(args);
  1408  
  1409          /*
  1410           * Search to see if name exists, and get back a pointer to it.
  1411           */
  1412          error = xfs_attr_node_hasname(args, &state);
  1413          if (error != -EEXIST)
  1414                  goto out_release;
                        ^^^^^^^^^^^^^^^^
state can be NULL.

  1415  
  1416          /*
  1417           * Get the value, local or "remote"
  1418           */
  1419          blk = &state->path.blk[state->path.active - 1];
  1420          error = xfs_attr3_leaf_getvalue(blk->bp, args);
  1421  
  1422          /*
  1423           * If not in a transaction, we have to release all the buffers.
  1424           */
  1425  out_release:
  1426          for (i = 0; i < state->path.active; i++) {
                                ^^^^^^^^^^^^^^^^^^
Dereference

  1427                  xfs_trans_brelse(args->trans, state->path.blk[i].bp);
  1428                  state->path.blk[i].bp = NULL;
  1429          }
  1430  
  1431          if (state)
                    ^^^^^
To late.

  1432                  xfs_da_state_free(state);
  1433          return error;
  1434  }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug report] xfs: Add xfs_has_attr and subroutines
  2020-07-28 11:57 [bug report] xfs: Add xfs_has_attr and subroutines dan.carpenter
@ 2020-07-28 17:49 ` Allison Collins
  0 siblings, 0 replies; 2+ messages in thread
From: Allison Collins @ 2020-07-28 17:49 UTC (permalink / raw)
  To: dan.carpenter; +Cc: linux-xfs



On 7/28/20 4:57 AM, dan.carpenter@oracle.com wrote:
> Hello Allison Collins,
> 
> The patch cfe3d8821c6f: "xfs: Add xfs_has_attr and subroutines" from
> Jul 20, 2020, leads to the following Smatch warning:
> 
> 	fs/xfs/libxfs/xfs_attr.c:1431 xfs_attr_node_get()
> 	warn: variable dereferenced before check 'state' (see line 1426)
> 
> fs/xfs/libxfs/xfs_attr.c
>    1398  STATIC int
>    1399  xfs_attr_node_get(
>    1400          struct xfs_da_args      *args)
>    1401  {
>    1402          struct xfs_da_state     *state;
>    1403          struct xfs_da_state_blk *blk;
>    1404          int                     i;
>    1405          int                     error;
>    1406
>    1407          trace_xfs_attr_node_get(args);
>    1408
>    1409          /*
>    1410           * Search to see if name exists, and get back a pointer to it.
>    1411           */
>    1412          error = xfs_attr_node_hasname(args, &state);
>    1413          if (error != -EEXIST)
>    1414                  goto out_release;
>                          ^^^^^^^^^^^^^^^^
> state can be NULL.
> 
>    1415
>    1416          /*
>    1417           * Get the value, local or "remote"
>    1418           */
>    1419          blk = &state->path.blk[state->path.active - 1];
>    1420          error = xfs_attr3_leaf_getvalue(blk->bp, args);
>    1421
>    1422          /*
>    1423           * If not in a transaction, we have to release all the buffers.
>    1424           */
>    1425  out_release:
>    1426          for (i = 0; i < state->path.active; i++) {
>                                  ^^^^^^^^^^^^^^^^^^
> Dereference
> 
>    1427                  xfs_trans_brelse(args->trans, state->path.blk[i].bp);
>    1428                  state->path.blk[i].bp = NULL;
>    1429          }
>    1430
>    1431          if (state)
>                      ^^^^^
> To late.
> 
>    1432                  xfs_da_state_free(state);
>    1433          return error;
>    1434  }
> 
> regards,
> dan carpenter
> 
Thanks for the catch, with send a patch for this

Allison

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28 11:57 [bug report] xfs: Add xfs_has_attr and subroutines dan.carpenter
2020-07-28 17:49 ` Allison Collins

Linux-XFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-xfs/0 linux-xfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-xfs linux-xfs/ https://lore.kernel.org/linux-xfs \
		linux-xfs@vger.kernel.org
	public-inbox-index linux-xfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-xfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git