From 72e7f067a0d7671b372c23ee727b39b5b24f93da Mon Sep 17 00:00:00 2001
From: guiyao <guiyao@huawei.com>
Date: Wed, 15 Apr 2020 20:13:26 +0000
Subject: [PATCH] add device check in ismount process

Signed-off-by: guiyao <guiyao@huawei.com>
Signed-off-by: Shijie Luo <luoshijie1@huawei.com>
---
 lib/ext2fs/ismounted.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c
index 46d330d..2add4c0 100644
--- a/lib/ext2fs/ismounted.c
+++ b/lib/ext2fs/ismounted.c
@@ -98,6 +98,7 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file,
 {
 	struct mntent 	*mnt;
 	struct stat	st_buf;
+	struct stat dir_st_buf;
 	errcode_t	retval = 0;
 	dev_t		file_dev=0, file_rdev=0;
 	ino_t		file_ino=0;
@@ -128,24 +129,27 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file,
 	while ((mnt = getmntent (f)) != NULL) {
 		if (mnt->mnt_fsname[0] != '/')
 			continue;
-		if (stat(mnt->mnt_dir, &st_buf) != 0)
+		if (stat(mnt->mnt_dir, &dir_st_buf) != 0)
 			continue;
 		if (strcmp(file, mnt->mnt_fsname) == 0) {
-			if (file_rdev && (file_rdev != st_buf.st_dev)) {
+			if (file_rdev && (file_rdev == dir_st_buf.st_dev)) {
 #ifdef DEBUG
 				printf("Bogus entry in %s!  "
 				       "(%s does not exist)\n",
 				       mtab_file, mnt->mnt_dir);
 #endif /* DEBUG */
-				continue;
+				break;
 			}
-			break;
+			continue;
 		}
 		if (stat(mnt->mnt_fsname, &st_buf) == 0) {
 			if (ext2fsP_is_disk_device(st_buf.st_mode)) {
 #ifndef __GNU__
-				if (file_rdev && (file_rdev == st_buf.st_rdev))
-					break;
+				if (file_rdev && (file_rdev == st_buf.st_rdev)){
+					if (file_rdev == dir_st_buf.st_dev) {
+						break;
+					}
+                }
 				if (check_loop_mounted(mnt->mnt_fsname,
 						st_buf.st_rdev, file_dev,
 						file_ino) == 1)
-- 
1.8.3.1

