Skip to contentSkip to conversation

xfs: fix return of uninitialized value in variable error

PATCH In review Colin King 3 participants 4 messages Apr 9, 2021

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 xfs: fix return of uninitialized value in variable error

From: Colin Ian King <[email protected]>

A previous commit removed a call to xfs_attr3_leaf_read that assigned an error return code to variable error. We now have a few early error return paths to label 'out' that return error if error is set; however error now is uninitialized so potentially garbage is being returned. Fix this by setting error to zero to restore the original behaviour where error was zero at the label 'restart'.

Addresses-Coverity: ("Uninitialized scalar variable")

Fixes 07120f1abdff ("xfs: Add xfs_has_attr and subroutines")
---
 fs/xfs/libxfs/xfs_attr.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/libxfs/xfs_attr.c +1 -0
index 472b3039eabb..902e5f7e6642 100644
@@ -928,6 +928,7 @@ xfs_attr_node_addname(
 	 * Search to see if name already exists, and get back a pointer
 	 * to where it should go.
 	 */
+	error = 0;
 	retval = xfs_attr_node_hasname(args, &state);
 	if (retval != -ENOATTR && retval != -EEXIST)
 		goto out;
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Colin King

From: Colin Ian King <[email protected]>

A previous commit removed a call to xfs_attr3_leaf_read that assigned an error return code to variable error. We now have a few early error return paths to label 'out' that return error if error is set; however error now is uninitialized so potentially garbage is being returned. Fix this by setting error to zero to restore the original behaviour where error was zero at the label 'restart'.

Addresses-Coverity: ("Uninitialized scalar variable")

Fixes 07120f1abdff ("xfs: Add xfs_has_attr and subroutines")
---
 fs/xfs/libxfs/xfs_attr.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/libxfs/xfs_attr.c +0 -0
index 472b3039eabb..902e5f7e6642 100644

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 934

Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +1 -0
@@ -928,6 +928,7 @@ xfs_attr_node_addname(
 	 * Search to see if name already exists, and get back a pointer
 	 * to where it should go.
 	 */
+	error = 0;
 	retval = xfs_attr_node_hasname(args, &state);
 	if (retval != -ENOATTR && retval != -EEXIST)
 		goto out;

I think it would be nicer to initialize at the top of the function as opposed to try and "preserve" historical behavior, but that nit aside:

Quoted 3 lines
Signature · 1 line
2.30.2
#2 lore raw
Quoted 18 lines · Brian Foster
Quoted 17 lines · Colin King

From: Colin Ian King <[email protected]>

A previous commit removed a call to xfs_attr3_leaf_read that assigned an error return code to variable error. We now have a few early error return paths to label 'out' that return error if error is set; however error now is uninitialized so potentially garbage is being returned. Fix this by setting error to zero to restore the original behaviour where error was zero at the label 'restart'.

Addresses-Coverity: ("Uninitialized scalar variable")

Fixes 07120f1abdff ("xfs: Add xfs_has_attr and subroutines")
---
 fs/xfs/libxfs/xfs_attr.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines

fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 934

Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c +1 -0
index 472b3039eabb..902e5f7e6642 100644
@@ -928,6 +928,7 @@ xfs_attr_node_addname(
 	 * Search to see if name already exists, and get back a pointer
 	 * to where it should go.
 	 */
+	error = 0;
 	retval = xfs_attr_node_hasname(args, &state);
 	if (retval != -ENOATTR && retval != -EEXIST)
 		goto out;

I think it would be nicer to initialize at the top of the function as opposed to try and "preserve" historical behavior, but that nit aside:

I did think about that, but this fix does ensure it's zero'd for each iteration rather than just the once, so it should catch any code changes later on that may loop back to this point were error is non-zero.

Quoted 7 lines
Quoted 3 lines
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#3 lore raw
In reply to Colin King
Quoted 10 lines · Colin King

From: Colin Ian King <[email protected]>

A previous commit removed a call to xfs_attr3_leaf_read that assigned an error return code to variable error. We now have a few early error return paths to label 'out' that return error if error is set; however error now is uninitialized so potentially garbage is being returned. Fix this by setting error to zero to restore the original behaviour where error was zero at the label 'restart'.

Quoted 3 lines

Addresses-Coverity: ("Uninitialized scalar variable")

Fixes 07120f1abdff ("xfs: Add xfs_has_attr and subroutines")

Looks correct to me...

--D

Quoted 19 lines
---
 fs/xfs/libxfs/xfs_attr.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/libxfs/xfs_attr.c +1 -0
index 472b3039eabb..902e5f7e6642 100644
@@ -928,6 +928,7 @@ xfs_attr_node_addname(
 	 * Search to see if name already exists, and get back a pointer
 	 * to where it should go.
 	 */
+	error = 0;
 	retval = xfs_attr_node_hasname(args, &state);
 	if (retval != -ENOATTR && retval != -EEXIST)
 		goto out;
Signature · 1 line
2.30.2