Skip to contentSkip to conversation

xfs: Initialize variables in xfs_alloc_get_rec before using them

PATCH In review Carlos Maiolino 3 participants 3 messages Jun 28, 2018 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfs: Initialize variables in xfs_alloc_get_rec before using them

Make sure we initialize *bno and *len, before jumping to out_bad_rec label, and risk calling xfs_warn() with uninitialized variables.

Coverity: 100898
Coverity: 1437081
Coverity: 1437129
Coverity: 1437191
Coverity: 1437201
Coverity: 1437212
Coverity: 1437341

---

This is based on Darrick's suggestion, although, I believe initializing *bno and *len before testing if *len is empty or not is a bit more clear than changing xfs_warn() to use rec->alloc.ar_startblock and rec->alloc.ar_blockcount directly.

 fs/xfs/libxfs/xfs_alloc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +3 -2
index eef466260d43..75dbdc14c45f 100644
@@ -223,12 +223,13 @@ xfs_alloc_get_rec(
 	error = xfs_btree_get_rec(cur, &rec, stat);
 	if (error || !(*stat))
 		return error;
-	if (rec->alloc.ar_blockcount == 0)
-		goto out_bad_rec;
 
 	*bno = be32_to_cpu(rec->alloc.ar_startblock);
 	*len = be32_to_cpu(rec->alloc.ar_blockcount);
 
+	if (*len == 0)
+		goto out_bad_rec;
+
 	/* check for valid extent range, including overflow */
 	if (!xfs_verify_agbno(mp, agno, *bno))
 		goto out_bad_rec;
Signature · 1 line
2.14.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Carlos Maiolino

Make sure we initialize *bno and *len, before jumping to out_bad_rec label, and risk calling xfs_warn() with uninitialized variables.

Coverity: 100898
Coverity: 1437081
Coverity: 1437129
Coverity: 1437191
Coverity: 1437201
Coverity: 1437212
Coverity: 1437341

Quoted 2 lines

---

Quoted 36 lines

This is based on Darrick's suggestion, although, I believe initializing *bno and *len before testing if *len is empty or not is a bit more clear than changing xfs_warn() to use rec->alloc.ar_startblock and rec->alloc.ar_blockcount directly.

 fs/xfs/libxfs/xfs_alloc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +3 -2
index eef466260d43..75dbdc14c45f 100644
@@ -223,12 +223,13 @@ xfs_alloc_get_rec(
 	error = xfs_btree_get_rec(cur, &rec, stat);
 	if (error || !(*stat))
 		return error;
-	if (rec->alloc.ar_blockcount == 0)
-		goto out_bad_rec;
 
 	*bno = be32_to_cpu(rec->alloc.ar_startblock);
 	*len = be32_to_cpu(rec->alloc.ar_blockcount);
 
+	if (*len == 0)
+		goto out_bad_rec;
+
 	/* check for valid extent range, including overflow */
 	if (!xfs_verify_agbno(mp, agno, *bno))
 		goto out_bad_rec;
Signature · 6 lines
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by on v2 1/1
#2 lore raw
In reply to Carlos Maiolino
Quoted 11 lines · Carlos Maiolino

Make sure we initialize *bno and *len, before jumping to out_bad_rec label, and risk calling xfs_warn() with uninitialized variables.

Coverity: 100898
Coverity: 1437081
Coverity: 1437129
Coverity: 1437191
Coverity: 1437201
Coverity: 1437212
Coverity: 1437341

Looks ok,

--D

Quoted 37 lines

---

This is based on Darrick's suggestion, although, I believe initializing *bno and *len before testing if *len is empty or not is a bit more clear than changing xfs_warn() to use rec->alloc.ar_startblock and rec->alloc.ar_blockcount directly.

 fs/xfs/libxfs/xfs_alloc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +3 -2
index eef466260d43..75dbdc14c45f 100644
@@ -223,12 +223,13 @@ xfs_alloc_get_rec(
 	error = xfs_btree_get_rec(cur, &rec, stat);
 	if (error || !(*stat))
 		return error;
-	if (rec->alloc.ar_blockcount == 0)
-		goto out_bad_rec;
 
 	*bno = be32_to_cpu(rec->alloc.ar_startblock);
 	*len = be32_to_cpu(rec->alloc.ar_blockcount);
 
+	if (*len == 0)
+		goto out_bad_rec;
+
 	/* check for valid extent range, including overflow */
 	if (!xfs_verify_agbno(mp, agno, *bno))
 		goto out_bad_rec;
Signature · 6 lines
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html