Blame SOURCES/e2fsprogs-1.45.6-libsupport-fix-potental-NULL-pointer-dereferences-in.patch

a77133
From c976fd2e72678a171693d2b6333c2c499ef4d588 Mon Sep 17 00:00:00 2001
a77133
From: Lukas Czerner <lczerner@redhat.com>
a77133
Date: Fri, 6 Aug 2021 11:58:20 +0200
a77133
Subject: [PATCH 44/46] libsupport: fix potental NULL pointer dereferences in
a77133
 quota functions
a77133
Content-Type: text/plain
a77133
a77133
get_dq() function can fail when the memory allocation fails and so we
a77133
could end up dereferencing NULL pointer. Fix it.
a77133
a77133
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
a77133
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
a77133
---
a77133
 lib/support/mkquota.c      | 8 ++++++--
a77133
 lib/support/quotaio_tree.c | 2 +-
a77133
 2 files changed, 7 insertions(+), 3 deletions(-)
a77133
a77133
diff --git a/lib/support/mkquota.c b/lib/support/mkquota.c
a77133
index ef50c9ab..280b1046 100644
a77133
--- a/lib/support/mkquota.c
a77133
+++ b/lib/support/mkquota.c
a77133
@@ -432,7 +432,8 @@ void quota_data_sub(quota_ctx_t qctx, struct ext2_inode_large *inode,
a77133
 		dict = qctx->quota_dict[qtype];
a77133
 		if (dict) {
a77133
 			dq = get_dq(dict, get_qid(inode, qtype));
a77133
-			dq->dq_dqb.dqb_curspace -= space;
a77133
+			if (dq)
a77133
+				dq->dq_dqb.dqb_curspace -= space;
a77133
 		}
a77133
 	}
a77133
 }
a77133
@@ -459,7 +460,8 @@ void quota_data_inodes(quota_ctx_t qctx, struct ext2_inode_large *inode,
a77133
 		dict = qctx->quota_dict[qtype];
a77133
 		if (dict) {
a77133
 			dq = get_dq(dict, get_qid(inode, qtype));
a77133
-			dq->dq_dqb.dqb_curinodes += adjust;
a77133
+			if (dq)
a77133
+				dq->dq_dqb.dqb_curinodes += adjust;
a77133
 		}
a77133
 	}
a77133
 }
a77133
@@ -532,6 +534,8 @@ static int scan_dquots_callback(struct dquot *dquot, void *cb_data)
a77133
 	struct dquot *dq;
a77133
 
a77133
 	dq = get_dq(quota_dict, dquot->dq_id);
a77133
+	if (!dq)
a77133
+		return -1;
a77133
 	dq->dq_id = dquot->dq_id;
a77133
 	dq->dq_flags |= DQF_SEEN;
a77133
 
a77133
diff --git a/lib/support/quotaio_tree.c b/lib/support/quotaio_tree.c
a77133
index 6cc4fb5b..5910e637 100644
a77133
--- a/lib/support/quotaio_tree.c
a77133
+++ b/lib/support/quotaio_tree.c
a77133
@@ -601,7 +601,7 @@ static int report_tree(struct dquot *dquot, unsigned int blk, int depth,
a77133
 	__le32 *ref = (__le32 *) buf;
a77133
 
a77133
 	if (!buf)
a77133
-		return 0;
a77133
+		return -1;
a77133
 
a77133
 	read_blk(dquot->dq_h, blk, buf);
a77133
 	if (depth == QT_TREEDEPTH - 1) {
a77133
-- 
a77133
2.35.1
a77133