]> www.infradead.org Git - mtd-utils.git/commitdiff
fs-tests: integck: limit the recursion depth
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Tue, 26 Apr 2011 09:47:48 +0000 (12:47 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Fri, 29 Apr 2011 18:19:58 +0000 (21:19 +0300)
I observes segfaults in integck test, and unfortunately I do not have the core
file to investigate the problem. But I see one possibility for the test to
segfault - it has unbounded recursion. Limit the maximum recursion depth.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
tests/fs-tests/integrity/integck.c

index 1dd424ed024b3c4e2b825623e855012f944cbef9..a35b7aec1c9719bdf8357adb8e47ba656ffe9e6d 100644 (file)
@@ -2094,11 +2094,20 @@ static int operate_on_file(struct file_info *file)
        return 0;
 }
 
+/*
+ * The operate on entry function is recursive because it calls
+ * 'operate_on_dir()' which calls 'operate_on_entry()' again. This variable is
+ * used to limit the recursion depth.
+ */
+static int recursion_depth;
+
 /* Randomly select something to do with a directory entry */
 static int operate_on_entry(struct dir_entry_info *entry)
 {
        int ret = 0;
 
+       recursion_depth += 1;
+
        /* 1 time in 1000 rename */
        if (random_no(1000) == 0)
                ret = rename_entry(entry);
@@ -2111,7 +2120,7 @@ static int operate_on_entry(struct dir_entry_info *entry)
                /* If shrinking, 1 time in 50, remove a directory */
                if (shrink && random_no(50) == 0)
                        ret = dir_remove(entry->dir);
-               else
+               else if (recursion_depth < 20)
                        ret = operate_on_dir(entry->dir);
        } else if (entry->type == 'f') {
                /* If shrinking, 1 time in 10, remove a file */
@@ -2124,6 +2133,8 @@ static int operate_on_entry(struct dir_entry_info *entry)
                else
                        ret = operate_on_file(entry->file);
        }
+
+       recursion_depth -= 1;
        return ret;
 }