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

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