Blame SOURCES/e2fsprogs-1.45.6-libext2fs-fix-unexpected-NULL-variable.patch

a77133
From 92d055879d510a1a51315301ea788445cd11aacb Mon Sep 17 00:00:00 2001
a77133
From: Lukas Czerner <lczerner@redhat.com>
a77133
Date: Fri, 6 Aug 2021 11:58:16 +0200
a77133
Subject: [PATCH 40/46] libext2fs: fix unexpected NULL variable
a77133
Content-Type: text/plain
a77133
a77133
The ext2fs_check_mount_point() function can be called with mtpt being
a77133
NULL as for example from ext2fs_check_if_mounted(). However in the
a77133
is_swap_device condition we use the mtpt in strncpy without checking
a77133
whether it is non-null first.
a77133
a77133
This should not be a problem on linux since the previous attempt to open
a77133
the device exclusively would have prevented us from ever reaching the
a77133
problematic strncpy. However it's still a bug and can cause problems on
a77133
other systems, fix it by conditioning strncpy on mtpt not being null.
a77133
a77133
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
a77133
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
a77133
---
a77133
 lib/ext2fs/ismounted.c | 3 ++-
a77133
 1 file changed, 2 insertions(+), 1 deletion(-)
a77133
a77133
diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c
a77133
index 46d330d9..c28475d4 100644
a77133
--- a/lib/ext2fs/ismounted.c
a77133
+++ b/lib/ext2fs/ismounted.c
a77133
@@ -393,7 +393,8 @@ errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
a77133
 
a77133
 	if (is_swap_device(device)) {
a77133
 		*mount_flags = EXT2_MF_MOUNTED | EXT2_MF_SWAP;
a77133
-		strncpy(mtpt, "<swap>", mtlen);
a77133
+		if (mtpt)
a77133
+			strncpy(mtpt, "<swap>", mtlen);
a77133
 	} else {
a77133
 #ifdef HAVE_SETMNTENT
a77133
 		retval = check_mntent(device, mount_flags, mtpt, mtlen);
a77133
-- 
a77133
2.35.1
a77133