diff mbox series

[5/6] super1: check fd before passing to get_dev_size() in add_to_super1()

Message ID 20240220105612.31058-6-mateusz.kusiak@intel.com (mailing list archive)
State Accepted
Headers show
Series SAST fixes | expand

Commit Message

Mateusz Kusiak Feb. 20, 2024, 10:56 a.m. UTC
Check if file descriptor is valid before passing it to get_dev_size() in
add_to_super().

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
---
 super1.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/super1.c b/super1.c
index 871d19f0398c..5439b7bb1240 100644
--- a/super1.c
+++ b/super1.c
@@ -1752,7 +1752,10 @@  static int add_to_super1(struct supertype *st, mdu_disk_info_t *dk,
 	di->devname = devname;
 	di->disk = *dk;
 	di->data_offset = data_offset;
-	get_dev_size(fd, NULL, &di->dev_size);
+
+	if (is_fd_valid(fd))
+		get_dev_size(fd, NULL, &di->dev_size);
+
 	di->next = NULL;
 	*dip = di;