]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Fix open_container
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 687a2ce22b887c943b180257c535896485965883..4581fbd45a178f4796692c7b1d6b88e4b93fb855 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1352,6 +1352,20 @@ int open_container(int fd)
                        continue;
                if (de->d_name[0] == '.')
                        continue;
+               /* Need to make sure it is a container and not a volume */
+               sprintf(e, "/%s/md/metadata_version", de->d_name);
+               dfd = open(path, O_RDONLY);
+               if (dfd < 0)
+                       continue;
+               n = read(dfd, buf, sizeof(buf));
+               close(dfd);
+               if (n <= 0 || (unsigned)n >= sizeof(buf))
+                       continue;
+               buf[n] = 0;
+               if (strncmp(buf, "external", 8) != 0 ||
+                   n < 10 ||
+                   buf[9] == '/')
+                       continue;
                sprintf(e, "/%s/dev", de->d_name);
                dfd = open(path, O_RDONLY);
                if (dfd < 0)