Skip to contentSkip to conversation

Monitor: dev should be a block file in waitclean

PATCH In review Zhilong Liu 1 participant 2 messages Feb 14, 2017 – Feb 24, 2017 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Monitor: dev should be a block file in waitclean

mdadm --wait-clean /dev/mdX, the dev should
be a block file, otherwise fd2devnm returns
NULL and triggers core dumped.

Monitor.c +10 -0
index 802a9d9..d16ac49 100644
@@ -1060,7 +1060,17 @@ int WaitClean(char *dev, int sock, int verbose)
 	struct mdinfo *mdi;
 	int rv = 1;
 	char devnm[32];
+	struct stat stb;
 
+	if (stat(dev, &stb) != 0) {
+		pr_err("Cannot find %s: %s\n", dev,
+			strerror(errno));
+		return 2;
+	}
+	if ((S_IFMT & stb.st_mode) != S_IFBLK) {
+		pr_err("%s is not a block device.\n", dev);
+		return 2;
+	}
 	fd = open(dev, O_RDONLY);
 	if (fd < 0) {
 		if (verbose)
Signature · 1 line
2.6.6
author
#1 lore raw

Hi, Jes;
I just wanted to ping and see if this could get a review:

Quoted 28 lines · Zhilong Liu

mdadm --wait-clean /dev/mdX, the dev should
be a block file, otherwise fd2devnm returns
NULL and triggers core dumped.

Monitor.c +10 -0
index 802a9d9..d16ac49 100644
@@ -1060,7 +1060,17 @@ int WaitClean(char *dev, int sock, int verbose)
  	struct mdinfo *mdi;
  	int rv = 1;
  	char devnm[32];
+	struct stat stb;
 
+	if (stat(dev, &stb) != 0) {
+		pr_err("Cannot find %s: %s\n", dev,
+			strerror(errno));
+		return 2;
+	}
+	if ((S_IFMT & stb.st_mode) != S_IFBLK) {
+		pr_err("%s is not a block device.\n", dev);
+		return 2;
+	}
  	fd = open(dev, O_RDONLY);
  	if (fd < 0) {
  		if (verbose)