Whamcloud - gitweb
mmp: don't assume NUL termination for MMP strings
[tools/e2fsprogs.git] / lib / ext2fs / finddev.c
index 56b76df..cd85ef5 100644 (file)
@@ -5,11 +5,12 @@
  * Copyright (C) 2000 Theodore Ts'o.
  *
  * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
  * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #if HAVE_UNISTD_H
 #if HAVE_SYS_MKDEV_H
 #include <sys/mkdev.h>
 #endif
+#ifdef HAVE_SYS_SYSMACROS_H
+#include <sys/sysmacros.h>
+#endif
 
 #include "ext2_fs.h"
 #include "ext2fs.h"
+#include "ext2fsP.h"
 
 struct dir_list {
        char    *name;
@@ -99,7 +104,8 @@ static int scan_dir(char *dirname, dev_t device, struct dir_list **list,
                        goto skip_to_next;
                if (S_ISDIR(st.st_mode))
                        add_to_dirlist(path, list);
-               if (S_ISBLK(st.st_mode) && st.st_rdev == device) {
+               if (ext2fsP_is_disk_device(st.st_mode) &&
+                   st.st_rdev == device) {
                        cp = malloc(strlen(path)+1);
                        if (!cp) {
                                closedir(dir);
@@ -127,6 +133,7 @@ char *ext2fs_find_block_device(dev_t device)
        struct dir_list *list = 0, *new_list = 0;
        struct dir_list *current;
        char    *ret_path = 0;
+       int    level = 0;
 
        /*
         * Add the starting directories to search...
@@ -153,6 +160,9 @@ char *ext2fs_find_block_device(dev_t device)
                if (list == 0) {
                        list = new_list;
                        new_list = 0;
+                       /* Avoid infinite loop */
+                       if (++level >= EXT2FS_MAX_NESTED_LINKS)
+                               break;
                }
        }
        free_dirlist(&list);